Sign in to follow this  
Followers 0
ovideo

search string in file?

4 posts in this topic

i need a function to search for a string in a file and i can't seem to find it in the help

i know _replacestringinfile would tell me if the string can be found in the file but i need a function that returns something (the number of the line where the string is found would be ideal)

any ideas, anyone?

Share this post


Link to post
Share on other sites



i need a function to search for a string in a file and i can't seem to find it in the help

i know _replacestringinfile would tell me if the string can be found in the file but i need a function that returns something (the number of the line where the string is found would be ideal)

any ideas, anyone?

You will have to write your own function to do that. Look at FileOpen, FileRead, FileClose, StringInStr, StringSplit, and _FileReadToArray.

If you want, we could help, but you fail to mention the input file type and the input file size. Is it a text file? Is it 100MB, 5MB, 1KB?

All this stuff is extremely important when considering how you are going to write a function that reads a file and searches for strings inside the file.

- The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

it is a text file, about 3-4MB in size

all i need to do is search for a string (which may contain line breaks) and read the line above it

edit: the string WILL contain line breaks

and another edit: thank you for offering to help but i'm sure you have better things to do :D

i'll work around it, that's part of the fun

Edited by ovideo

Share this post


Link to post
Share on other sites

it is a text file, about 3-4MB in size

all i need to do is search for a string (which may contain line breaks) and read the line above it

edit: the string WILL contain line breaks

and another edit: thank you for offering to help but i'm sure you have better things to do :)

i'll work around it, that's part of the fun

Hi! What is the line breaks, line feed?

Example

$string = FileRead("c:\test.txt")

$result = StringRegExp($string, "^.*\w", 1)

MsgBox(0, "", $result[0])

:)

Share this post


Link to post
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
Sign in to follow this  
Followers 0