Replace spaces in QString with backslash spaces

2019-09-10 05:43发布

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条回答
Summer. ? 凉城
2楼-- · 2019-09-10 06:20

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

myPath.replace(" ", "\\ ");
查看更多
登录 后发表回答