What is the regex expression for the special characters that is greater than 128 in the ASCII extended table?
I have a line with special characters like below, and every special char should be replaced with a space.
input ---> "H€ELLOŠŠŠŠWorld$"
output --> "H ELLO World$"
NB: $ is special character that has ASCII<128
To know ASCII<128 characters http://www.ascii-code.com/
Please try the following:
var re = new Regex(@"[\u0080-\uFFFF]");
var s = re.Replace("H€ELLOŠŠŠŠWorld. This is a sample 1234 $.", " ");
Console.WriteLine(s);
OUTPUT
H ELLO World. This is a sample 1234 $.
Why bother with regexes for this task?
var str = "H€ELLOŠŠŠŠWorld$";
var sb = new StringBuilder(str.Length);
foreach(var c in str)
sb.Append(c <= 128 ? c : ' ');
var result = sb.ToString();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.