nanobox1471 Posted February 24, 2018 Share Posted February 24, 2018 What I'm trying to do is rename a duplicate string in a file to make it unique. using _ReplaceStringInFile I am able to rename the first occurrence or all occurrences. Any suggestions how to alter my code to rename following occurrences until all instances have been changed. $file = @ScriptDir & "\test.ini" Global $sharename = IniReadSection ($file,"PrintList") For $x = 1 to UBound ($sharename) -1 If String ($sharename[$x][0]) = "ShareName" Then $str_replace = _ReplaceStringInFile ($file,"ShareName","ShareName0" &+ 1 ,1,0) If $str_replace = 1 Then ExitLoop EndIf EndIf Next ShellExecute ($file) ; to Verify Change to Document test.ini Link to comment Share on other sites More sharing options...
nanobox1471 Posted February 25, 2018 Author Share Posted February 25, 2018 NVM Figured it out... couldn't Use ShareName as both search string and replace string. Modified: $str_replace = _ReplaceStringInFile ($file,"ShareName","ShareName0" &+ 1 To: $str_replace = _ReplaceStringInFile ($file,"ShareName","PrintName0" & $x ,1,0) and all values were modified appropriately. Link to comment Share on other sites More sharing options...
Malkey Posted February 25, 2018 Share Posted February 25, 2018 This example appears to work. #include <File.au3> Local $iDup = 0 $file = "test.ini" Global $sharename = IniReadSection($file, "PrintList") For $x = 1 To UBound($sharename) - 1 If String($sharename[$x][0]) = "ShareName" Then $iDup += 1 $sharename[$x][0] &= StringRight("00" & $iDup, 2) EndIf Next IniWriteSection($file, "PrintList", $sharename) ShellExecute($file) ; to Verify Change to Document" nanobox1471 1 Link to comment Share on other sites More sharing options...
nanobox1471 Posted February 26, 2018 Author Share Posted February 26, 2018 Works like a charm... Thank You Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now