Jump to content

Best way to read the Text file


usera
 Share

Recommended Posts

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

usera,

I have never use FileReadToArray. any tips

Read 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? :shocked:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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? :shocked:

M23

Thanks! M23

Program passed.

usera

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...