Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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 :)

Never trouble another for what you can do for yourself.
  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...