Samanta
March 31st, 1999, 02:48 PM
Hi
How can i convert string "c:\a\b" to "c:\\a\\b" ?
thanx
How can i convert string "c:\a\b" to "c:\\a\\b" ?
thanx
|
Click to See Complete Forum and Search --> : How can i convert string "c:\a\b" to "c:\\a\\b" ? Samanta March 31st, 1999, 02:48 PM Hi How can i convert string "c:\a\b" to "c:\\a\\b" ? thanx Julius Ivanyi March 31st, 1999, 03:13 PM Hi just create a loop iterating through the characters of the string, copy each character from the string into a new string and whenever you find the '\' character, plug in another '\' character into the new string. HTH Julius Masaaki Onishi March 31st, 1999, 03:58 PM Hi. I had a same problem to do it before. But I solved it. If you have "c:\a\b", you must cut this string like "c:", "a" and "b". After this, CString str = CString("c:") + "\\" + "\\"; You will get "c:\\" and apply to "a" and combines them. If you try "\", the complier says error -> new line ... Does anyone has better idea? Regards. -Masaaki Onishi- Gomez Addams March 31st, 1999, 04:53 PM As usual, everyone has their own prefered method. Here is the pseudcode for mine. This will have problems with a CString testchar = startofstring while( testchar is not null ) { if( testchar is a slash ) { move entire string right one place (including null) insert another slash advance testchar two places (for two slashes) } else advance testchar one place } If I gave you real code it would spoil your fun :) Samanta March 31st, 1999, 05:05 PM Thank u all for such fast responding :) actualy i am trying to get TCHAR type filename from GetSaveFile function(which is giving me "c:\a\b\") and give it to wmfDC.Create("c:\\a\\b\\blah.wmf"). I understood all ur suggestsions...thought there is any special function for this... Thanx Samanta forever ;-) Gomez Addams March 31st, 1999, 06:15 PM At that level, single backslashes should work. Are they being 'escaped' ? A possibly easier thing to do would be to switch them all to forward slashes. This little loop will do it. while( TRUE ) { char * cptr = strchr( filename, '\\' ); if( cptr ) *cptr = '/'; else break; } Most function will accept forward slashes in path names. Maybe I should say, many functions will. Masaaki Onishi March 31st, 1999, 06:44 PM Hi. You are lucky. CString filename = "C:\Masaaki\Masaaki\Masaaki.txt"; CString one = "\\"; CString two = CString("\\") + "\\"; int n = filename.Replace(one, two); // filename is now "C:\\Masaaki\\Masaaki\\Masaaki.txt"; I just check this by the debugger, so probably this is OK. Replace is only avaliabe for VC6.0. Hope for help. Masaaki Onishi- sally March 31st, 1999, 08:05 PM CString str("c:\a\b"); str.Replace("\", "\\"); Sally Sally March 31st, 1999, 08:05 PM CString str("c:\a\b"); str.Replace("\", "\\"); Sally Masaaki Onishi March 31st, 1999, 08:37 PM Hi. I posted this above. Can you explain this. So I use "\\" and "\\" + "\\" D:\MyProjects\VC\ReBars\MyDialog.cpp(58) : error C2017: illegal escape sequence D:\MyProjects\VC\ReBars\MyDialog.cpp(58) : error C2017: illegal escape sequence D:\MyProjects\VC\ReBars\MyDialog.cpp(58) : error C2001: newline in constant D:\MyProjects\VC\ReBars\MyDialog.cpp(61) : error C2143: syntax error : missing ')' before 'tag::id' D:\MyProjects\VC\ReBars\MyDialog.cpp(61) : error C2661: 'Replace' : no overloaded function takes 1 parameters Error executing cl.exe. cdmahesh April 12th, 2001, 04:17 AM Hi str = "c:\a\b" str.Replace("\","\\\\"); i think this will work. bye Mahesh Kumar C D cdmahesh April 12th, 2001, 04:18 AM Hi str = "c:\a\b" str.Replace("\","\\\\"); or u need to use 4 backslashes there to get 2 backslashes. i think this will work. bye Mahesh Kumar C D codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |