[Qt-interest] how to shift the content in a line
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Wed Feb 11 14:03:06 CET 2009
Knoll Oliver, ITS-CMT-SUI-SL-PDC-FIN-DEV wrote on Wednesday, February 11, 2009 1:53 PM:
> Ravi_Kalepalli wrote on Wednesday, February 11, 2009 5:24 AM:
>
>> ...
>> Now I have to append a string at the middle (LINE No 4), how to shift
>> the 1 and add the string.
>
> 1. newText = Parse the text file (=read) until you hit the place
>...
> 5. end :)
To make more use of Qt you could also do:
QFile file("password.txt");
QString text = file.readAll();
int position = ...; // find the position at which you want to insert the new text
// e.g. using a QRegExp or whatever
text.insert(position, newText);
// now overwrite the content of file with 'text', using a QTextStream etc.
...
Not the most performant (and resource-friendly) solution, but assuming that you don't need to parse MBytes of text (but rather of the kind you have shown in your first post) it should be sufficient - and easy to understand, and it let's Qt handle the "hard stuff" (I always say: "Let other people to the hard work" ;)
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list