0

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.

M. P.
  • 91
  • 2
  • 10

1 Answers1

4

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

myPath.replace(" ", "\\ ");
talamaki
  • 5,324
  • 1
  • 27
  • 40