1, bool QString :: startsWith // string begins XX, returns true, the second parameters can be set case-sensitive
QString str = "Bananas"; str.startsWith("Ban"); // returns true str.startsWith("Car"); // returns false
2, bool QString :: endsWith // string ends XX, returns false, the second parameters can be set case-sensitive
QString str = "Bananas"; str.endsWith("anas"); // returns true str.endsWith("pple"); // returns false
3, QString QString :: trimmed () // return with no spaces before and after the string
QString str = " lots\t of\nwhitespace\r\n "; str = str.trimmed(); // str == "lots\t of\nwhitespace"
4, QString & QString :: remove (int position, int n) // specify the location to start deleting n characters, returns that character references
QString s = "Montreal"; s.remove(1, 4); // s == "Meal"
5, int QString :: indexOf () // Returns the index position specified position from the beginning of the first occurrence, or -1 not found. The second parameter may be set case-sensitive
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
6、int QString::lastIndexOf()
// returns the index of the last occurrence of the string str in this string, searching backward from index position. If from is -1 (the default), the search starts from the last character; if from is -2, the penultimate character, and so on. If str is not found, returns -1. The second parameter may be set case-sensitive
QString x = "crazy azimuths"; QString y = "az"; x.lastIndexOf(y); // returns 6 x.lastIndexOf(y, 6); // returns 6 x.lastIndexOf(y, 5); // returns 2 x.lastIndexOf(y, 1); // returns -1
7, QString QString :: right (int n) const // Returns a substring of the rightmost string of n characters.
QString x = "Pineapple"; QString y = x.right(5); // y == "apple"
8, QString QString :: left (int n) const // Returns a substring of the string leftmost n characters.
QString x = "Pineapple"; QString y = x.left(4); // y == "Pine"
9, QString QString :: mid (int position, int n = -1) const // Returns a string containing n characters of the string, starting from a position specified by the index.
QString x = "Nine pineapples"; QString y = x.mid(5, 4); // y == "pine" QString z = x.mid(5); // z == "pineapples"