1、组合字符常用arg()函数
QString test=QString("_haha_%1_hehe%2") .arg("ee").arg("aa"); //test="_haha_ee_heheaa"
eg:arg(const QString &a, int fieldWidth = 0, QChar fillChar = QLatin1Char( ' ' )) const 参数1.连接的字符;参数2.字符所占据的宽度;参数3.如果字符的宽度小于参数2的宽度,则用参数3的字符填充。
如下图所示:fieldWidth >0 ,代表的右对齐; fieldWidth <0,代表的左对齐。如下图所示:
.
2、提取具有分割符的字符串用section()函数
QString QString::section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const //参数1,代表分隔符;参数2,提取字符的起始位置;参数3,提取字符的结束位置。
eg:
QString str;
QString csv = "forename,middlename,surname,phone";
QString path = "/usr/local/bin/myapp"; // First field is empty
QString::SectionFlag flag = QString::SectionSkipEmpty; //Treat empty fields as if they don't exist, i.e. they are not considered as far as start and end are concerned.
str = csv.section(',', 2, 2); // str == "surname"。("forename,middlename,surname,phone")
str = path.section('/', 3, 4); // str == "bin/myapp"。("/usr/local/bin/myapp")
str = path.section('/', 3, 3, flag); // str == "myapp" ("/usr/local/bin/myapp")空字符串开始的地方不被当做开始或结束的地方
3、QString在结构体中是直接当做4个字节的指针来占用内存的