I have a string which is something like "c:\x\y\z"
I want it in the form "c://x//y//z"
I tried using stdString.replace("\","//");
but it doesn't work.
Any suggestions?
I have a string which is something like "c:\x\y\z"
I want it in the form "c://x//y//z"
I tried using stdString.replace("\","//");
but it doesn't work.
Any suggestions?
If your string is "c:\x\y\z"
, there are no \
in your string. \
denotes an escape character. Change your string to "c:\\x\\y\\z"
.
Also, note how replace
works - http://www.cplusplus.com/reference/string/string/replace/
I don't think you can replace one character '\\'
with two "//"
directly. (I might be proven wrong).
Alternative:
std::stringstream ss;
for ( int i = 0 ; i < str.size() ; i++ )
{
if ( str[i] == '\\' )
ss << "//";
else
ss << str[i];
}
str = ss.str();
stdString.replace("\\","\/\/"); ?