将QString按逗号分割后,中间加入一个换行符,组成新的qstring,c++代码
时间: 2023-02-12 18:21:28 浏览: 93
863568206#guang.github.io#2019-7-26-QString与C++字符串类型的相互转换1
下面是将 QString 按逗号分割后,在每个逗号后面加入换行符的 C++ 代码:
```
QString originalString = "item1,item2,item3";
QString newString;
QStringList list = originalString.split(",");
for(int i = 0; i < list.size(); i++) {
newString += list.at(i) + "\n";
}
```
如果要在每个逗号前面加入换行符,可以这样:
```
QString originalString = "item1,item2,item3";
QString newString;
QStringList list = originalString.split(",");
for(int i = 0; i < list.size(); i++) {
newString += "\n" + list.at(i);
}
```
如果要在每个逗号前后都加入换行符,可以这样:
```
QString originalString = "item1,item2,item3";
QString newString;
QStringList list = originalString.split(",");
for(int i = 0; i < list.size(); i++) {
newString += "\n" + list.at(i) + "\n";
}
```
阅读全文