We help IT Professionals succeed at work.

Replace all instances

michael1174
michael1174 asked
on
428 Views
Last Modified: 2012-06-05
Hello, I'm trying to replace all instances of, for example, the > sign in a string.

I know I can do a string.replace(">",">").  But this only replaces once instance.  What is the best way that I can replace all instances?

I've tried, but for some reason its not working and my text has alot of amp; in it after its done processing.

foreach (char c in value)
   {
       value = Replace(">", ">");
   }
Comment
Watch Question

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
HttpServerUtility.HtmlEncode is exactly what I needed, thank you.

Author

Commented:
Hello, I am using the Server.HtmlEncode but for some reason if a wierd string like "!@#$%^&*()_+-={}|[]\:";'<>?,./" (without the quotes) is passed in, the html is not structured correctly.

Do you have any other suggestions?
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.