0

I want to replace

! = change

@ = static(does not)

$ = Want to replace

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

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

5 Answers 5

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Regex.Replace("@!$!", "!(.*)!", "replacement value");

Comments

0

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

Comments

0

also, check out Rubular, a great RegEx Tester.

Comments

-1

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.

2 Comments

The OP has asked how to build a house, and you have given him the address to a hardware store.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.