在Qt中编辑文件

麦克风

假设我有一些.csv文件,如下所示:

1,2,5,5,
0,5,6,9,
3,2,5,7,
1,2,3,6,

如何删除每行末尾的','符号?

ps例如,我知道如何在行尾处清理空格- file.readLine().trimmed();,但是对于其他标志,该如何做呢,我不知道。

春天

假设您已经知道如何逐行读取,则此粗略方法有效:

QString testStr = QString("1,2,5,5,");

QStringList testList = testStr.split(",");
qDebug() << "testList" << testList;

testList.removeLast();
qDebug() << "testList" << testList;

testStr = testList.join(",");
qDebug() << "testStr" << testStr;

// 输出

testList ("1", "2", "5", "5", "") 
testList ("1", "2", "5", "5") 
testStr "1,2,5,5" 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章