Is Replace in C # the same as replaceAll in Java?
Replace
replaceAll
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 .
You are looking for the Regex.Replace() method:
Regex.Replace()
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.
string.Replace()
Replacing the base line is currently in progress.
If you want to use regex, use:
username = Regex.Replace(username, "\\([^\\(]*\\)", "");