Common qstringlist Methods

Source: Internet
Author: User

The qstringlist class provides a string list.

Inherited from qlist <qstring>, it provides access and fast insertion and Removal Based on quick indexing.

Its member functions are used to operate the string list, as shown in figure

Append (), insert (), replace (), removeall (), removeat (), removefirst (), removelast (), and removeone ()

1. Add a string

You can use append () or <, as shown in figure

Qstringlist fonts;

Fonts <"Arial" <"Helvetica" <"times" <"Courier ";

// Fonts: ["Arial", "Helvetica", "Times", "Courier"]

2. Use join () to merge strings ()

Qstring STR = fonts. Join (",");

// STR = "Arial, Helvetica, times, courier"

3. Split string

Qstring STR = "Arial, Helvetica, times, courier ";

Qstringlist list1 = Str. Split (",");

// List1: ["Arial", "Helvetica", "", "Times", "Courier"]

Qstringlist list2 = Str. Split (",", qstring: skipemptyparts );

// List2: ["Arial", "Helvetica", "Times", "Courier"]

That is to say, if qstring: skipemptyparts exists, null items will not appear in the result. By default, null items are retained.

4. Index

The indexof () function returns the first index of the given string.

The lastindexof () function returns the last index of the string.

5. replaceinstrings ()

Qstringlist files;

Files <"$ qtdir/src/MOC. Y"

<"$ Qtdir/src/MOC. L"

<"$ Qtdir/include/qconfig. H ";

Files. replaceinstrings ("$ qtdir", "/usr/lib/Qt ");

// Files: ["/usr/lib/QT/src/MOC. Y",...]

6. Filter ()

You can extract a new list that contains only one specific string (or matches a specific regular expression ):

Qstringlist list;

List <"Bill Murray" <"John Doe" <"Bill Clinton ";

Qstringlist result;

Result = List. Filter ("bill ");

// Result: ["Bill Murray", "Bill Clinton"]

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.