regex to convert j to character

  • Thread starter Thread starter Mo
  • Start date Start date
M

Mo

Hi,

What is the regex to replace & # 1 0 6 ; to character? Any Ideas?

Thanks,
Mo
 
Mo said:
Hi,

What is the regex to replace & # 1 0 6 ; to character? Any Ideas?

Thanks,
Mo

Wherefore is a regex here?

someString.Replace("j", "j");
 
Hi,
What is the regex to replace & # 1 0 6 ; to character? Any Ideas?

Thanks,
Mo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top