用反斜杠空格替换 QString 中的空格 [英] Replace spaces in QString with backslash spaces

查看:61
本文介绍了用反斜杠空格替换 QString 中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用反斜杠空格替换 QString 中的空格.

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

我有:QString myPath =/home/matt/my file.txt

我需要:QString myPath =/home/matt/my\file.txt

我尝试使用 myPath.replace(" ", "\ "); 但不幸的是编译器将其作为转义序列中断.

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

推荐答案

编译器使用 \ 作为字符串中的转义字符.您将需要两个反斜杠.

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

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

这篇关于用反斜杠空格替换 QString 中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆