Use of the Qstring class (all-encompassing, extremely convenient)

Source: Internet
Author: User

The Qstring class of QT provides a convenient interface for string manipulation.

    1. Causes a character to fill a string, meaning that all characters in the string are replaced by the equal-length ch.
Qstring::fill (Qchar ch, int size =-1)

Cases:

     QString str = "Berlin";     Str.fill (' z ');     str = = "Zzzzzz"     str.fill (' A ', 2);     str = = "AA"

2, find the same string str from the string.

int Qstring::indexof (const QString & str, int from = 0, qt::casesensitivity cs = qt::casesensitive) const

For example:

QString x = "Sticky question";     QString y = "sti";     X.indexof (y);               Returns 0     x.indexof (y, 1);            Returns     X.indexof (Y, ten);           Returns     X.indexof (Y, one);           Returns-1

3 Inserting a string at the specified location

QString & Qstring::insert (int position, const QString & str)

For example:

     QString str = "Meal";     Str.insert (1, QString ("Ontr"));     str = = "Montreal"

3 to determine if the string is empty.

BOOL Qstring::isempty () const

Such as:

     QString (). IsEmpty ();            Returns True     QString (""). IsEmpty ();          Returns True     QString ("x"). IsEmpty ();         Returns false     QString ("abc"). IsEmpty ();       Returns false

4. Determine if the string exists.

BOOL Qstring::isnull () const

For example:

     QString (). IsNull ();             Returns True     QString (""). IsNull ();           Returns false     QString ("abc"). IsNull ();        Returns false

5, the string is truncated from left to right

QString qstring::left (int n) const

For example:

     QString x = "Pineapple";     QString y = x.left (4);      y = = "Pine"

6. Intercept the string from the middle.

QString qstring::mid (int position, int n =-1) const

For example:

  QString x = "Nine pineapples";     QString y = X.mid (5, 4);            y = = "Pine"     QString z = x.mid (5);               z = = "Pineapples"

7. Remove a character from the middle of the string.

QString & Qstring::remove (int position, int n)

For example:

     QString s = "Montreal";     S.remove (1, 4);     s = = "Meal"

8, replace some characters in the string.

QString & Qstring::replace (int position, int n, const QString & After)

For example:

     QString x = "Say yes!";     QString y = "no";     X.replace (4, 3, y);     x = = "Say no!"

9, cutting a string with a character. (frequently used recently)

QString qstring::section (qchar Sep, int start, int end =-1, sectionflags flags = sectiondefault) const

For example:

   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"

10, convert integer, float, or other type to qstring

QString & Qstring::setnum (uint n, int base = 10)

Similar to the many overloaded functions, want to learn more, or to see the QT Help document.

Http://www.cnblogs.com/onlycxue/archive/2012/10/30/2746902.html

Use of the Qstring class (all-encompassing, extremely convenient)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.