PDA

View Full Version : How to write something in line of txt file



Zergi
24th December 2007, 09:43
Hi

I have a little problem, exactly i have no idea how to replace sentens in txt file...
In txt file i have something like thath


save option =0
dir exp=0

Do u know how to change value 0 to 1 in dir exp?

Best regards

wysota
24th December 2007, 10:01
If you don't change the length, you can seek to the position in the file and simply overwrite the character. But if you want something more complicated, you'll have to read the file into memory (into a string or sth), replace what you want and write everything back.

high_flyer
24th December 2007, 10:02
There are several options:
1. It looks you are dealing with an ini file.
So you might want to have a look at QSettings, which does all this for you.
2. if for some reason you can't use QSettigns, but you know exactly what you are looking for in the text (meaning, the text is not arbitrary ) you can just use QString::replace()

3. If the text to replace is not fixed, then you can use QRegExp in conjunction with QString.
4. If none of the above helped you, you might want to look QTextEdit facilities, but in contrast to the previous points, its not as little code as the others.