fguihen Posted May 18, 2007 Posted May 18, 2007 i have a string, and it has to become a filename. the problem is it contains backslashes in many places. ive tried using the string.replace method to replace the \ with blank spaces but it doesnt work. its the same story with doubble quote charachters (the " charachter).what am i doing wrong? Quote
Administrators PlausiblyDamp Posted May 18, 2007 Administrators Posted May 18, 2007 What code are you using to remove the backslashes as there is no reason why this should fail. Dim s as string = "ssdfdsf\sdfsdfdsf" s=s.Replace("\"," ") string s = "dsfsdf\\fdsfsdf"; s = s.Replace('\\',' '); either should work. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
MrPaul Posted May 19, 2007 Posted May 19, 2007 String methods What code are you using to remove the backslashes as there is no reason why this should fail. As a guess, I would say fguihen may be expecting the Replace method to affect the actual string instance it is invoked on. It is useful to remember that the string type is immutable, meaning that an individual string instance cannot be modified, instead a new string must be created. This applies to all string methods, such as Concat, Remove, Trim, ToUpper and ToLower: 'Incorrect myString.ToUpper() 'Correct myString = myString.ToUpper() Good luck :) Quote Never trouble another for what you can do for yourself.
Leaders snarfblam Posted May 19, 2007 Leaders Posted May 19, 2007 Re: String methods Good catch, Mister Paul. You know, assuming that this is the case, I wouldn't have caught that, even if I saw the code. Even now I find myself stumped from time to time when I use the String.Replace method. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.