Convert a multiline QString into a one line QString

百般思念 提交于 2019-12-07 05:54:24

Put your text into a QStringList, and use QStringList::join(), e.g.

QStringList doc;
[...]
Text = Stream.readLine();
Text = Text.simplified();
doc << Text;
[...]
QString final = doc.join(" ");

You could use the readAll function of QTextStream in order to get a string containing all your text and then use the replace function of QString in order to remove new lines:

QString oneLineText = Stream.readAll().replace("\n"," ").simplified();

If you have a large file it is better to use the readLine function.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!