Replace spaces in QString with backslash spaces

我怕爱的太早我们不能终老 提交于 2019-12-12 04:28:58

问题


I need to replace spaces in a QString with backslash spaces.

I have: QString myPath = /home/matt/my file.txt

I need: QString myPath = /home/matt/my\ file.txt

I tried using myPath.replace(" ", "\ "); but unfortunately the compiler interrupts this as an escape sequence.


回答1:


The compiler uses \ as an escape character in strings. You will need two backslashes.

myPath.replace(" ", "\\ ");


来源:https://stackoverflow.com/questions/41033583/replace-spaces-in-qstring-with-backslash-spaces

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