0

I have the following string

string s = "efile:ReturnState/efile:ReturnDataState/efile:processBO/composition/forms/IT204CP";

I would like to replace the efile: name space with an empty string and would like the result to be as follows

"ReturnState/ReturnDataState/processBO/composition/forms/IT204CP";

I also would like to know if there is a more generic way of doing this, as in something where I can replace any namespace like we see above and not just efile?

Ben
  • 2,433
  • 5
  • 39
  • 69
user3375390
  • 99
  • 1
  • 10

2 Answers2

1

You don't need Regex here; Regex is meant for pattern matching but you just need to replace a string literal with another one (empty string).

s = s.Replace(@"efile:","")

will remove all instances of efile:

if you want generic, then simply replace the "efile:" literal with a string variable and set the variable to whatever you want to remove.

DeanOC
  • 7,142
  • 6
  • 42
  • 56
1

As DeanOC mentioned, there's no need to use a regex for this, but if you really want to, the regex is really straightforward

string result = Regex.Replace(s, "efile:", "");
Iain Fraser
  • 6,578
  • 8
  • 43
  • 68