Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

It seems simple enough, right? Well, I don't know.

Here's the code I'm trying:

input = Regex.Replace(input, "", "");

However, I'm receiving an error,

ArgumentException was unhandled - parsing "" - Illegal at end of pattern.

How do I do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
627 views
Welcome To Ask or Share your Answers For Others

1 Answer

The first one should be "", not "". It works like this:

  • You have written "".
  • This translates to the sequence in a string.
  • The regex engine then reads this, which translates as backslash which isn't escaping anything, so it throws an error.

With regex, it's much easier to use a "verbatim string". In this case the verbatim string would be @"". When using verbatim strings you only have to consider escaping for the regex engine, as backslashes are treated literally. The second string will also be @"", as it will not be interpreted by the regex engine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...