Multiple Replace in a string

  • Thread starter Thread starter JS
  • Start date Start date
J

JS

Is it possible to do multiple replaces in a string?

Example: I'm trying to replace all of the spaces with "%20" and "#" with
"%23", etc. I also need to replace the "?", "!", " ' ", etc.

I know I can do this with:
thisString.Replace(" ", "%20")
thisString.Replace("#", "%23")

But, I'm trying to find a way to do this one line of code.

Any Ideas?

TIA

JS
 
JS,
Have you tried:
thisString.Replace(" ", "%20")
thisString.Replace("#", "%23")

thisString = thisString.Replace(" ", "%20").Replace("#", "%23").
Example: I'm trying to replace all of the spaces with "%20" and "#" with
"%23", etc. I also need to replace the "?", "!", " ' ", etc.
Although you may be approaching enough replacements that I would consider
using a StringBuilder instead. I would encapsulate the use of the
StringBuilder into a function, or possibly even a class.

Hope this helps
Jay
 
Back
Top