M Mo Feb 15, 2007 #1 Hi, What is the regex to replace & # 1 0 6 ; to character? Any Ideas? Thanks, Mo
M marss Feb 15, 2007 #2 Mo said: Hi, What is the regex to replace & # 1 0 6 ; to character? Any Ideas? Thanks, Mo Click to expand... Wherefore is a regex here? someString.Replace("j", "j");
Mo said: Hi, What is the regex to replace & # 1 0 6 ; to character? Any Ideas? Thanks, Mo Click to expand... Wherefore is a regex here? someString.Replace("j", "j");
H Hans Kesting Feb 15, 2007 #3 Hi, What is the regex to replace & # 1 0 6 ; to character? Any Ideas? Thanks, Mo Click to expand... You can't "replace" with regex, only "find" (which can then be used to "replace"). Try this to replace all &#<number>; codes with the correct character: private static string DecodeMatch(Match m) { string s = m.ToString(); // "&#" 0-9 ";" string s2 = s.Substring(2, s.Length-3); int i = Int32.Parse(s2); Char c = Convert.ToChar(i); return c.ToString(); } public string Decode(string s) { string result = Regex.Replace(s, @"&#[0-9]+;", new MatchEvaluator(Formatter.DeencodeMatch)); return result; } Hans Kesting
Hi, What is the regex to replace & # 1 0 6 ; to character? Any Ideas? Thanks, Mo Click to expand... You can't "replace" with regex, only "find" (which can then be used to "replace"). Try this to replace all &#<number>; codes with the correct character: private static string DecodeMatch(Match m) { string s = m.ToString(); // "&#" 0-9 ";" string s2 = s.Substring(2, s.Length-3); int i = Int32.Parse(s2); Char c = Convert.ToChar(i); return c.ToString(); } public string Decode(string s) { string result = Regex.Replace(s, @"&#[0-9]+;", new MatchEvaluator(Formatter.DeencodeMatch)); return result; } Hans Kesting