路径中斜杠与反斜杠的转化?
如路径C:/testA\\testB\testC.txt
我想把字符串中的“\\”和“\”都变成“/”,该怎么实现?
我先抛砖引玉啦
QString path = "C:/testA\\testB\testC.txt";
QString tmpPath;
if(path.contains("\\"))
{
tmpPath = path.replace("\\","/",Qt::CaseInsensitive);
}
if(tmpPath .contains("\"))
{
tmpPath = tmpPath .replace("\","/",Qt::CaseInsensitive);
}
但是报错:error C2001: newline in constant
[解决办法]
一个\ 表示转义的,\\才表示一个\,\\\\才表示\\
[解决办法]
也就是说,将
QString path = "C:/testA\\testB\testC.txt";
[解决办法]
QDir::toNativeSeparators
这个问题我记得曾经有说过