views:

94

answers:

5

I want to replace

! = change

@ = static(does not)

$ = Want to replace

I got a sting like this @!$! How do I replace the $ with something else?

EDIT: I need to use Regex as the string may appear anywhere!

+3  A: 

You don't need a regular expression, just use the String.Replace method:

String result = input.Replace("$", "somethingElse");


As a side note: The way that you would do this with a regular expression would be like this:

String result = Regex.Replace(input, @"\$", "somethingElse");

Notice that I have escaped the $ with a backslash since $ usually means match the end of the string.

Andrew Hare
A: 

Using the String class' .Replace() method would do the trick but, if you really want to use RegEx, this is a great RegEx site that I use quite often.

Regular Expression Library

You should be able to find what you're looking for there.

Ken
The OP has asked how to build a house, and you have given him the address to a hardware store.
Charlie Salts
I'm assuming that this guy get paid for what he dose and I thought it better to give him the tools he needs to accomplish his job instead of doing his job for him and giving him the answer. Sort of the "Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime." approach. I suppose I could have ALSO given him the answer.
Ken
A: 

Why do you want some RegExp for string replacement. You can just use string.Replace() fundtion.

Neil
+2  A: 

Take a look at System.Text.RegularExpressions.Regex.Replace method.

Regex.Replace("@!$!", "!(.*)!", "replacement value");
Bryan Denny
Yap, this is what I wanted!
Jonathan Shepherd
A: 

also, check out Rubular, a great RegEx Tester.

Brandon