How to get a line number that contains a specified string in a text file?
Example text file contains:
Red
White
Yellow
Green
How to get "Yellow" line number? and can i write a string in a specified line, lets say i want to write a string in line 2?
Edit: If you want to write a string in that line, the best way would be to replace that line with the new one. In the following example i'm replacing all occurences of "Yellow" with "Yellow Submarine"
Or you want to replace a specific line:
To find a line in a text file, you need to read the lines from the start of the file until you find it:
If you want to change a line in a file, you have to read the entire file and write it back with the changed line: