usera Posted October 20, 2010 Share Posted October 20, 2010 Greeting, I have a text file I need to do some replaces. for example: \\orange\file3 \\apple\file1 \\apple\file2 \\apple\file4 \\orange\file5 .. .. I want to replace the apple to banana, and just ignore the line has orange. the result I am looking for is like below: \\banana\file1 \\banana\file2 \\banana\file4 right now I am using code as below. the replace part is ok, but very hard to ignore the orange line. because I can not control to read next line While 1 $line = FileReadLine($filer) if ...then ExitLoop If @error = -1 Then ExitLoop $write=$write & $part11 & $result2 & $part12 & $part3 Wend kind of hard for me to do that, is any good way to do it. Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 20, 2010 Moderators Share Posted October 20, 2010 usera,I would read the file into an array (using _FileReadToArray as you might have guessed) and then manipulate the data within the array. Use StringInStr to detect the "orange"s and then use _ArrayDelete to remove them - but start at the bottom and work up or you will run into problems. Then use StringReplace on the "apples" and finally _FileWriteFromArray to save the result.Be careful with the count in the [0] element though. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
usera Posted October 20, 2010 Author Share Posted October 20, 2010 usera, I would read the file into an array (using _FileReadToArray as you might have guessed) and then manipulate the data within the array. Use StringInStr to detect the "orange"s and then use _ArrayDelete to remove them - but start at the bottom and work up or you will run into problems. Then use StringReplace on the "apples" and finally _FileWriteFromArray to save the result. Be careful with the count in the [0] element though. M23 Thank you VERY VERY much for your feedback. I have never use FileReadToArray. any tips for now to control to read next line? is the idea to read whole file to a Array? then read the element one by one? thanks usera Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 20, 2010 Moderators Share Posted October 20, 2010 usera,I have never use FileReadToArray. any tipsRead the Help file and look at the example! is the idea to read whole file to a Array?Yes, as you will discover when you read the Help file. then read the element one by one?Yes again, using a For...Next loop - details of which can be found............................................in the Help file. Got the message? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
usera Posted October 20, 2010 Author Share Posted October 20, 2010 usera,Read the Help file and look at the example! Yes, as you will discover when you read the Help file. Yes again, using a For...Next loop - details of which can be found............................................in the Help file. Got the message? M23Thanks! M23Program passed.usera Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 20, 2010 Moderators Share Posted October 20, 2010 usera,When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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