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
QString character erase function
提问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
回答by zozermania
You can use
您可以使用
line.replace(QString(" "), QString(""));