当前位置:网站首页>General use of qstringlist
General use of qstringlist
2022-07-01 22:44:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Reference blog :https://blog.csdn.net/u013360881/article/details/52170487
QStringList initialization
QStringList qstrList;
qstrList<<"Android" << "Qt Creator" << "Java" << "C++";
QStringListIterator strIterator(qstrList);
while (strIterator.hasNext())
qDebug() << strIterator.next() << endl;
Here we use QStringList add to QString character string , use << To add a string , amount to Java in List Of add() Method .
Let's learn about QList Methods
1. Add string append() QStringList Can pass append(), Or use << To add List Elements , Such as
qstrList.append("python");
qstrList << "PHP" ;
2. Insert string insert() Insert string insert Method can insert a string into the... We specify list The location of :
qstrList.insert(0,"C#");
The first parameter is where we want to insert , The following parameters represent the values we want to insert . 3. Replace string replace() adopt replace() Method we can replace list The value of a position in the
qstrList.replace(0,"Web");
The first parameter is the position we want to replace , The following parameters represent the values we want to replace . 4. Delete string removeAt(), removeFirst(), removeLast(), and removeOne() We can use the method name , Infer the specific function of the method , Select the corresponding method according to the actual needs : Here's to say removeOne() Method , He means to delete a specific value , The parameter is us list Contents of Li , Its definition is : bool removeOne(const T &value) , The return value is bool type , Let's write an example of usage
bool isflag = qstrList.removeOne("C#");// Delete a specified element , Delete successful return true, Delete failed return fasle
qDebug() << isflag << endl;
int n = qstrList.removeAll("Java");// Delete all specified elements , Returns the number of deleted elements
qDebug() << n << endl;
qstrList.removeAt(2);// Delete the third element
qstrList.removeFirst();// Delete first element
qstrList.removeLast();// Delete the last element
Next let's learn QStringList Methods
1. Merge strings using join( )
QString str = fonts.join(",");
// str == "Android,Qt Creator,Java,C++"
2. Split string
QString str = "Android,Qt Creator, ,Java,C++";
QStringList list1 = str.split(",");
// list1: [ "Android", "Qt Creator"," ", "Java", "C++" ]
QStringList list2 = str.split(",", QString::SkipEmptyParts);
// list2:[ "Android", "Qt Creator", "Java", "C++" ]
That is to say, if there is QString::SkipEmptyParts, Empty items will not appear in the result . By default , Blank items are reserved 3. Indexes IndexOf() The index() function returns the index of the first occurrence of a given string . and lastIndexOf() function , Returns the index of the last occurrence of a string .
QStringList qstrList;
qstrList<<"Java" << "Android" << "Qt Creator" << "Java" << "C++";
int index = qstrList.indexOf("Java");// return 0
int index = qstrList.indexOf("Java");// return 3
4. Replace replaceInStrings()
QStringList files;
files << "$file/src/moc/moc.y" << "$file/src/moc/moc.l" << "$file/include/qconfig.h";
files.replaceInStrings("$file", "/usr/file");
// files: [ "/usr/file/src/moc/moc.y", ...]
5. Filter filter() Allows you to extract a new list containing only those strings containing a specific string ( Or match a specific regular expression ):
QStringList list;
list << "Bill Murray" << "John Doe" << "Bill Clinton";
QStringList result;
result = list.filter("Bill");
// result: ["Bill Murray", "Bill Clinton"]
// When comparing strings
//Qt::CaseSensitive Search is case sensitive
//Qt::CaseInSensitive Case insensitive
result = list.filter("bill",Qt::CaseInSensitive);
// result: ["Bill Murray", "Bill Clinton"]
summary :
QStringList Class provides a list of strings . QStringList Inherited from QList < QString >. And QList equally ,QStringList Is implicitly shared . It provides fast index based access , And quick insert and delete . Passing a list of strings as a value parameter is fast and safe . QList All functions of the also apply to QStringList. for example , You can use isEmpty() To test whether the list is empty , You can call things like append()、prepend()、insert()、replace()、removeAll()、removeAt()、removeFirst() and removeOne() To modify the QStringList Function of . Besides ,QStringList Provides some convenient functions , Make it easier to handle lists of strings
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/130299.html Link to the original text :https://javaforall.cn
边栏推荐
- Is PMP certificate really useful?
- What is the difference between PMP and NPDP?
- 分享一个一年经历两次裁员的程序员的一些感触
- The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
- 地图其他篇总目录
- Indicator trap: seven KPI mistakes that it leaders are prone to make
- MySQL数据库详细学习教程
- MySQL中对于索引的理解
- 详解Volatile关键字
- EasyExcel 复杂数据导出
猜你喜欢
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
互联网的智算架构设计
使用 Three.js 实现'雪糕'地球,让地球也凉爽一夏
Redis配置与优化
Mysql——》Innodb存储引擎的索引
功能测试报告的编写
Dark horse programmer - software testing - stage 06 2-linux and database-01-08 Chapter 1 - description of the content of the Linux operating system stage, description of the basic format and common fo
How to write a performance test plan
plantuml介绍与使用
Clean up system cache and free memory under Linux
随机推荐
RestTemplate 远程调用工具类
Operation category read is not supported in state standby
园区全光技术选型-中篇
MySQL MHA high availability configuration and failover
MySQL之MHA高可用配置及故障切换
详解Volatile关键字
Pytorch sharpening chapter | argmax and argmin functions
SAP UI5 应用开发教程之一百零四 - SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
详解JMM
Appium automated testing foundation - Supplement: introduction to desired capabilities parameters
Awoo's favorite problem (priority queue)
Mysql——》索引存储模型推演
【日常训练】66. 加一
Is PMP certificate really useful?
[ecological partner] Kunpeng system engineer training
【JetCache】JetCache的使用方法与步骤
# CutefishOS系统~
cvpr2022 human pose estiamtion
详解LockSupport的使用
C#/VB.NET 给PDF文档添加文本/图像水印