C++ QString 字符擦除功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19444424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:49:55  来源:igfitidea点击:

QString character erase function

c++qtqstring

提问by samvel1024

QString line = "example string";

Now I want to erase the space between 'example' and 'string' so that I get a string like this "examplestring". Is there a function in Qt which erases a character under the given index or should I write this function myself ?

现在我想删除 'example' 和 'string' 之间的空格,以便我得到一个像“examplestring”这样的字符串。Qt 中是否有一个函数可以擦除给定索引下的字符,还是我应该自己编写这个函数?

回答by vahancho

What about QString::remove(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive)function? You can use ' ' as a first argument. I.e.:

什么QString::remove(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive)功能?您可以使用“ ”作为第一个参数。IE:

QString line = "example string";
line.remove(' ');

回答by ratchet freak

line = line.remove(index,1);

see the documentation

查看文档

回答by zozermania

You can use

您可以使用

line.replace(QString(" "), QString(""));