C# How do I replace an actual asterisk character (*) in a Regex expression?
Posted
by fraXis
on Stack Overflow
See other posts from Stack Overflow
or by fraXis
Published on 2010-05-10T09:22:09Z
Indexed on
2010/05/10
9:24 UTC
Read the original article
Hit count: 232
Hello,
I have a statement:
I have a string such as
content = "* test *"
I want to search and replace it with so when I am done the string contains this:
content = "(*) test (*)"
My code is:
content = Regex.Replace(content, "*", "(*)");
But this causes an error in C# because it thinks that the * is part of the Regular Expressions Syntax.
How can I modify this code so it changes all asterisks in my string to (*) instead without causing a runtime error?
Thanks.
© Stack Overflow or respective owner