index at; returns the character at index i, or 0 if i exceeds the length of the string
const QString string( "abcdefgh" );
QChar ch = string.at( 4 );
QString toLower() //Convert to lowercase
QString toUpper() //Convert to uppercase
QString c("cle");
QString str=c.toUpper(); // str == "cle"
qDebug()<<str;
tail insert append; push_back
Head insert prepend; push_front
QString cer = "data";
cer.append("list");
cer.push_back("yes");
cer.prepend("like");
cer.push_front("good");
qDebug()<<cer;
Basic type conversion
s1.toUInt();
s1.toDouble();
s1.toFloat();
s1.toShort();
s1.toLong();
s1.toULongLong();
length
s1.size()
s1.count();
s1.length();
Returns true if the string is zero. A zero string is always empty.
QString a; // a.unicode() == 0,a.length() == 0
a.isNull(); // 真,因为a.unicode() == 0
a.isEmpty(); // 真
Compare
int a = QString::compare( "def", "abc" ); // a > 0
int b = QString::compare( "abc", "def" ); // b < 0
int c = QString::compare(" abc", "abc" ); // c == 0
Delete a character in the middle of a string
QString str = "Hello World!";
str.remove(5, 6); // str = "Hello!"
Insert character at specified position
QString str = "Hello!";
str.insert(5, QString(" World")); // str = "Hello World!"
QString::number integer conversion
int a = 20;
uint b =255;
QString::number(a);
QString::number(a,10);
QString::number(b);
QString::number(b,16);
The above are simple examples commonly used by QString; more examples are waiting for us to explore!