1 QString::arg()//用字符串变量参数依次替代字符串中·最小数值
例1:
QString str;
str = QString("%1 was born in %2.").arg("John").arg(1992);//srt = "John was born in 1992.";
其中 %1被替代为"John" %2被替代为"1992"
例2:
QString i = "iTest"; // current file‘s number
QString total = "totalTest"; // number of files to process
QString fileName = "fileNameTest"; // current file‘s name
QString status = QString("Processing file %1 of %2: %3").arg(i).arg(total).arg(fileName);
结果就是:"Processing file iTest of totalTest: fileNameTest"
2
QString str = " 123 4 ";
str = str.trimmed();//移除字符串2端的空白字符 结果为"123 4"
// str = str.simplified();//移除字符串2端的空白符 使用单个空格字符" "替代字符串中出现的空白字符 结果为 "123 4" 3
QString str = "1234";
QString str1 = "abxd";
str = str.insert(1,‘c‘);//在原字符串特定的位置插入另一个字符串或字符
//str = str.insert(1,"qq");
qDebug()<<str;//"1c234" 4 prepend();//在原字符串开头插入另一个字符串 5
QString str = "1234";
str = str.replace(1,2,"qwer");//从字符串的第几个位置起,用括号中的字符串替代掉原来的几个字符
qDebug()<<str;//结果为"1qwer4"
时间: 2024-10-14 01:04:12