问题
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