QT开发之字符串各种操作

1、字符串分割

split函数:第一个为分隔判断符,第二个为是否跳过空格。

例:QString a = "1,2,3,4,5,6,7";

QList ls;

ls = a.split(",");//ls = "1","2","3","4","5","6","7"

ls = a.split(",",QString::SkipEmptyParts);//ls = "1","2","3","4","5","6","7"

section函数:第一个为分隔判断符,第二个为判断起始位置,第三个为判断结束位置,位置为正时从左到右,为负是从右到左

例:QString a = "1,2,3,4,5,6,7";

QString b = a.section(",",1,1);//b=2,

QString b = a.section(",",-1,--1);//b=6

QString b = a.section(",",1,2);//b=2,3

2、判断字符在字符串中是否存在

QString::contains

例子:QString a = "1,2,3,4,5,6,7";

BOOL b = a.contains(",",Qt::CaseSensitive);//b=true

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bigtree_mfc/article/details/78086440
个人分类: Qt(跨平台)
上一篇QT开发之最简客户端
下一篇"<Module>"的类型初始值设定项引发异常的解决办法
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭