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?

5
  • Have you tried anything? This is a real simple regex... Commented Jun 23, 2015 at 1:05
  • possible duplicate of Learning Regular Expressions Commented Jun 23, 2015 at 1:05
  • regexr.com/3b8md Commented Jun 23, 2015 at 1:05
  • Just a guess but does your source XML (I'm assuming that is an xpath statement) specify a default namespace but you have a bunch of xpath that binds that namespace to efile? Commented Jun 23, 2015 at 1:13
  • Thanks Bas, this is what i exactly wanted. Commented Jun 24, 2015 at 17:40

2 Answers 2

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:", "");
Sign up to request clarification or add additional context in comments.

Comments

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.

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.