本文主要是讲QString的分割
这里,主要讲几个拆分字符的用法:
实例一,indexOf,mid,left,remove的用法:
#include #include #include int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str_source = "asda;weqw;123213;12312;asdsa";
str_source = str_source.trimmed();// 移除str_source字符串两端的空白字符
str_source += QString(";");
qDebug() << str_source;
while(str_source != "")
{
int nIndex = str_source.indexOf(";");
qDebug() << nIndex;// 由打印结果可以得到 nIndex 表示的是第一个分号之前的
// QString str_target = str_source.left(nIndex);// 这儿是取前nIndex位
QString str_target = str_source.mid(0,nIndex);// 从0开始取nIndex个
qDebug() << str_target;// 有结果可知 asda weqw 123213 12312 asdsa
str_source = str_source.remove(0,