Friday, July 24, 2009

Regex Expressions

Replace all special characters from string using REGEX EXPRESSION

If you want to replace special characters from string, then just need to use below expressio:
Regex.Replace(value, @"[^\w-\/]", "-")

Like:

ReplaceSpecialCharacter("(you don't need to insta/ll the software and you don't need--to register)")

private string ReplaceSpecialCharacter(string value)
{
return Regex.Replace(value, @"[^\w-\/]", "-");
}

Result:
-you-don-t-need-to-insta/ll-the-software-and-you-don-t-need--to-register-

No comments:

Post a Comment