Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Qt QString

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use Qt QString". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use Qt QString.

QString uses implicit sharing, also known as writeback replication. When two objects share the same data, the data content does not change, then there is no data replication, that is, the combination of deep copy and shallow copy.

When QString is used, strings are saved on contiguous memory blocks. The QString memory allocation strategy is as follows:

Range: 0 characters 20: 4 characters at a time.

Range 20,4084: twice at a time.

Range 4084 ~ ∞: 2048 characters at a time.

+: connection string

QString str1 = "I"; QString str2 = "LOVE"; QString str3 = "YOU"; QString str4 = str1 + str2 + str3; / / I LOVE YOU

Append (): append a string

QString str1 = "Hello"; QString str2 = "World"; str1.append (str2); / / Hello Worldstr1.append ("!"); / / Hello World!

Sprintf (): assign / concatenate / append strings

QString str;str.sprintf ("% s", "Nice to"); / / str = Nice tostr.sprintf ("% s% s", "Nice to", "meet you"); / / str = Nice to meet you

Arg (): ditto

QString str;str = QString ("My name is% 1, Isimm% 2 old."). Arg ("Paul"). Arg ("17"). / / str = My name is Paul, Ichimm 17 old.

Insert (): inserts a string at a specific location

QString str = "This is test code."; str.insert (8, "not"); / / str = This is not test code.

Prepend (): inserts a string at the beginning

QString str = "This is test code."; str.prepend ("Oh!"); / / str = Oh! This is test code.

Replace (): replaces some characters of the original string

QString str = "This is test code."; str.replace (13Jing 5, "data."); / / str = This is test data.

Trimmed (): removes white space characters from both ends of a string

QString str = "This is test code."; QString str1 = str.trimmed (); / / str = This is test code.

Simplified (): remove white space characters at both ends and replace them with a single space character ""

QString str = "This is test code."; QString str1 = str.simplified (); / / str = "This is test code."

StartsWith (): checks whether the string begins with a string, and Qt::CaseSensitive specifies

QString str = "This is test code."; bool result = str.startsWith ("This", Qt::CaseSensitive); / / result = trueQString str = "This is test code."; bool result = str.startsWith ("is", Qt::CaseSensitive); / / result = false

EndsWith (): the function is the same as above, check the end.

QString str = "This is test code."; bool result = str.endsWith ("code.", Qt::CaseSensitive); / / result = trueQString str = "This is test code."; bool result = str.endsWith ("is", Qt::CaseSensitive); / / result = false

Contains (): determines whether a string has ever appeared.

QString str = "This is test code."; bool result = str.contains ("code.", Qt::CaseSensitive); / / result = trueQString str = "This is test code."; bool result = str.contains ("what", Qt::CaseSensitive); / / result = false

LocaleAwareCompare (const QString&, const QString&): compares two strings, returns a negative value before being less than, returns 0 for equality, and returns a positive value for greater than. This comparison is based on the platform-related local character set.

QDebug ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report