一个QString类型字符串, 如何去掉其中的某一特定字符,比如“\n”.

linbegin 2010-04-28 04:48:22
RT
...全文
14813 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
soilde123 2010-05-04
  • 打赏
  • 举报
回复
simplified () 可以了
xiao4623581 2010-04-30
  • 打赏
  • 举报
回复
学习中
尹成 2010-04-30
  • 打赏
  • 举报
回复
str.replace(QString("\n"), QString(""));
gemfield 2010-04-30
  • 打赏
  • 举报
回复
QString gemfield("gem\nfield");

gemfield.remove("\n");

另外remove()方法的重载函数可以指定字母大小写是否敏感
csm2432 2010-04-30
  • 打赏
  • 举报
回复 5
QString QString::simplified () const
Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.

Whitespace means any character for which QChar::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

Example:

QString str = " lots\t of\nwhitespace\r\n ";
str = str.simplified();
// str == "lots of whitespace";
tingsking18 2010-04-28
  • 打赏
  • 举报
回复 2
str.replace(QString("\n"), QString(""));

21,495

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧