|
-
March 31st, 1999, 03:48 PM
#1
How can i convert string "c:\a\b" to "c:\\a\\b" ?
Hi
How can i convert string "c:\a\b" to "c:\\a\\b" ?
thanx
-
March 31st, 1999, 04:13 PM
#2
Re: How can i convert string "c:a" to "c:\a\b" ?
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
-
March 31st, 1999, 04:58 PM
#3
Re: This is not simple, isn't this.
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-
-
March 31st, 1999, 05:53 PM
#4
Re: How can i convert string "c:a" to "c:\a\b" ?
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 
-
March 31st, 1999, 06:05 PM
#5
Re: How can i convert string "c:a" to "c:a" ?
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 ;-)
-
March 31st, 1999, 07:15 PM
#6
Re: How can i convert string "c:a" to "c:a" ?
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.
-
March 31st, 1999, 07:44 PM
#7
Re: I got it. Only 4 lines- Replace()
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-
-
March 31st, 1999, 09:05 PM
#8
Re: How can i convert string "c:a" to "c:\a\b" ?
CString str("c:\a\b");
str.Replace("\", "\\");
Sally
-
March 31st, 1999, 09:37 PM
#9
Re: You is missing this.
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.
-
April 12th, 2001, 04:17 AM
#10
Re: How can i convert string "c:\a\b" to "c:\\a\\b" ?
Hi
str = "c:\a\b"
str.Replace("\","\\\\");
i think this will work.
bye
Mahesh Kumar C D
-
April 12th, 2001, 04:18 AM
#11
Re: How can i convert string "c:\a\b" to "c:\\a\\b" ?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|