0

i want to perform a global replacement equivalent code in c# for java script code below

text=text.replace(/-/g, '');

How can i do that?

Global replacement in javascript actually means this

var str="Mr Blue has a blue house and a blue car";
var n=str.replace(/blue/g,"red");

Mr Blue has a red house and a red car 
2
  • The javascript code should be text = text.replace(/-/g, "") Commented Nov 2, 2012 at 14:22
  • yes true you are but what for c#. Commented Nov 2, 2012 at 14:23

4 Answers 4

3
text = text.Replace( "-", "" );

Does global replacement, as shown in the example here: http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx

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

Comments

2

The output will contain the updated string.

string output = Regex.Replace(text, "-", "");

Comments

2

Try this:

text = text.Replace("-", "");

Comments

1
string s = s.Replace("scary", "not scary");

Comments

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.