当前位置:网站首页>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 34. 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
边栏推荐
- leetcode - 287. 寻找重复数
- 详解Kubernetes网络模型
- Learn MySQL from scratch - database and data table operations
- Two schemes of transforming the heat map of human posture estimation into coordinate points
- Smart micro mm32 multi-channel adc-dma configuration
- 详解ThreadLocal
- 447-哔哩哔哩面经1
- LC669. 修剪二叉搜索树
- Clean up system cache and free memory under Linux
- MySQL的存储过程
猜你喜欢
随机推荐
搜狗微信APP逆向(二)so层
keras训练的H5模型转tflite
Slope compensation
台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
MySQL stored procedure
详解JMM
Copy ‘XXXX‘ to effectively final temp variable
Compensation des créneaux horaires
MySQL中对于事务的理解
Indicator trap: seven KPI mistakes that it leaders are prone to make
#yyds干货盘点# 解决名企真题:扭蛋机
Sonic cloud real machine learning summary 6 - 1.4.1 server and agent deployment
SAP UI5 应用开发教程之一百零四 - SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
Yolov5.5 call local camera
Awoo's favorite problem (priority queue)
Smart micro mm32 multi-channel adc-dma configuration
[untitled]
QT版本华睿相机的Demo程序实现









