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