-
Use a character to fill the string, which means that all characters in the string are replaced by ch of equal length.
QString::fill(QChar ch, int size=-1)
QString str = "Berlin";
str.fill('z'); //str == "zzzzzz"
str.fill('A', 2); //str == "AA"
-
Find the same string str from the string
int QString::indexOf ( const QString & str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
QString x = "sticky question";
QString y = "sti";
x.indexOf(y); // returns 0
x.indexOf(y, 1); // returns 10
x.indexOf(y, 10); // returns 10
x.indexOf(y, 11); // returns -1
-
Insert string at specified position
QString & QString::insert ( int position, const QString & str )
QString str = "Meal";
str.insert(1, QString("ontr"));
// str == "Montreal"
- Determine whether the string is empty
bool QString::isEmpty () const
QString().isEmpty(); // returns true
QString("").isEmpty(); // returns true
QString("x").isEmpty(); // returns false
QString("abc").isEmpty(); // returns false
-
Determine whether the string exists
bool QString::isNull () const
QString().isNull(); // returns true
QString("").isNull(); // returns false
QString("abc").isNull(); // returns false
- Intercept string from left to right
QString QString::left (int n) const
QString x = "Pineapple";
QString y = x.left(4); // y == "Pine"
- Intercept the string from the middle
QString QString::mid (int position, int n = -1) const
QString x = "Nine pineapples";
QString y = x.mid(5, 4); // y == "pine"
QString z = x.mid(5); // z == "pineapples"
- Remove a character in the middle of the string
QString & QString::remove (int position, int n)
QString s = "Montreal";
s.remove(1, 4);
// s == "Meal"
- Replace some characters in the string
QString & QString::replace (int position, int n, const QString & after)
QString x = "Say yes!";
QString y = "no";
x.replace(4, 3, y);
// x == "Say no!"
- Cut a string with a character
QString QString::section (QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const
QString str;
QString csv = "forename,middlename,surname,phone";
QString path = "/usr/local/bin/myapp"; // First field is empty
QString::SectionFlag flag = QString::SectionSkipEmpty;
str = csv.section(',', 2, 2); // str == "surname"
str = path.section('/', 3, 4); // str == "bin/myapp"
str = path.section('/', 3, 3, flag); // str == "myapp"
- Convert integer, float or other types to QString
QString & QString::setNum (uint n, int base = 10)
Similarly, there are many multi-loaded functions. If you want to learn more, you still have to read the Qt help documentation.