471,610 Members | 1,316 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,610 software developers and data experts.

regex to convert j to character

Mo
Hi,

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

Thanks,
Mo

Feb 15 '07 #1
2 1789

Mo wrote:
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");

Feb 15 '07 #2
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
Feb 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by snthampi | last post: by
6 posts views Thread by snt | last post: by
2 posts views Thread by BenI | last post: by
11 posts views Thread by BenI | last post: by
40 posts views Thread by Tameem | last post: by
2 posts views Thread by christopher taylor | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.