PDA

View Full Version : DocuMentation item



impeteperry
30th August 2008, 21:06
Hi,
In the documentation for Qt-4.4,l at
http://doc.trolltech.com/4.4/qstring.html#replace
I think? there might be a minor error?
QString & QString::replace ( int position, int n, const QString & after )
Replaces n characters from the specified index position with the string after, and returns a reference to this string.
Example:
QString x = "Say yes!";
QString y = "no";
x.replace(4, 3, y);
// x == "Say no!"
I think there should be an "!" after the "no".

As an old man that has trouble reading "coded" instructions, I find these little examples very, very helpful. I just wish there were more of them.

Thanks

jacek
30th August 2008, 21:24
I think there should be an "!" after the "no".
There is one.

impeteperry
30th August 2008, 21:29
I see "yes!"
and
I see "no"
where is the "!" in "no"?

jacek
30th August 2008, 21:41
where is the "!" in "no"?
Here:

// x == "Say no!"
I've just cut & pasted the above line from the docs.

impeteperry
31st August 2008, 02:10
OK, I went back to my example, and low and behold I understand!

Stasting with the 4th charter, you are replacing the next 3 characters (yes) with the second string (no)

Thanks very much for your kind indulgence, I feel like a fool

wysota
1st September 2008, 06:23
Errare humanum est :)

lyuts
1st September 2008, 09:02
Why not use .arg() method?



QString x = QString("Say %1!");
...
use x.arg("yes");
or
use x.arg("no");

wysota
1st September 2008, 09:08
Because it's the documentation of QString::replace, not QString::arg.