Replace with C # and replaceAll in Java

Is Replace in C # the same as replaceAll in Java?

I'm trying to replace something in brackets, but it doesn't seem to work in C #. I need the result to be just blah.

 string username = "blah (blabla)"; userName = userName.Replace("\\([^\\(]*\\)", ""); 

It works when I use it here .

+7
source share
2 answers

You are looking for the Regex.Replace() method:

 string username = "blah (blabla)"; Regex rgx = new Regex("\\([^\\(]*\\")); userName = rgx.Replace(input, ""); 

The string.Replace() method only handles this, replaces the string - it does not cover the regular expression.

+11
source

Replacing the base line is currently in progress.

If you want to use regex, use:

 username = Regex.Replace(username, "\\([^\\(]*\\)", ""); 
+3
source

All Articles