QT Common class--qstring

Source: Internet
Author: User

Qstring has some aspects with the use of string in C + +, such as appending a string to another string, and also using "+". There are also append functions and so on.

Here is an example of some of the qstring specific functions that are commonly used:

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

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, 10); Returns X.indexof (Y, 11); 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

4. Determine if the string exists.

BOOL Qstring::isnull () const

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

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

QString & Qstring::setnum (uint n, int base = 10)
If we want to check whether a string starts or ends with something, we can use the StartsWith () and EndsWith () functions: if (Url.startswith ("http:") && Url.endswith (". PNG "))    

  

QT Common class--qstring

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.