Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace character '\'

Status
Not open for further replies.

giahan

Programmer
Sep 1, 2000
139
US

I have a string lile 'c:\dir1\subdir1\filename'. How do I rewrite that string as 'c:\\dir1\\subdir1\\filename'?
Thank you

GH
 
#include <afx.h>
int main()
{
CString aStr1 = &quot;c:\\dir1\\subdir1\\filename&quot;;
CString aStr2;

do{
int i = aStr1.Find('\\');
if (i>-1) {
aStr2 += aStr1.Left(i+1);
aStr2 +=&quot;\\&quot;;
aStr1 = aStr1.Right(aStr1.GetLength() - i-1);
}else {
aStr2 +=aStr1;
break;
}
}while(1);

printf(&quot;%s\n&quot;, aStr2);

return 0;
}
 
Or... just do

CString aStr1 = &quot;c:\\dir1\\subdir1\\filename&quot;;

aStr1.Replace(&quot;\\&quot;,&quot;\\\\&quot;);

Matt


 
That's not what I am looking for. I have:
str1= &quot;c:\dir1\sub1\file1&quot;
and I'd like to convert str1 into str2 and str2 has the value as:
str2=&quot;c:\\dir1\\sub1\\file1&quot;

Thank you
GH
 
That should be what you need.
You should be aware that in c language '\\' means character \ .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top