I have the same problem specifying it as:
Regex.Replace("?", "&#(.+?);", Chr(CInt("$1")))
You are using an expression as the 3th argument. The _result_ of this expression
will have $1 substituted by the first group.
So $1 is just $1 as the argument of Chr which gives an error.
You need to use a Matchevaluator (a function that gets called for each match)
:
http://msdn.microsoft.com/library/d...regularexpressionsregexclassreplacetopic1.asp
Why don't you just use Server.HTMLdecode?
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "
http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
string ToASCII(Match m)
{
string match = m.Groups[1].ToString();
char ASCII = (char)Convert.ToInt32(match);
return ASCII.ToString();
}
</script>
<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%
Response.Write("<BR>Regex solution<BR>");
Response.Write(Regex.Replace("ab?cd", "&#(.+?);", new
MatchEvaluator(ToASCII)));
Response.Write("<BR>Server.HtmlDecode solution<BR>");
Response.Write(Server.HtmlDecode("ab?cd"));
%>
</div>
</form>
</body>
</html>
Let me know if you have any more questions...
Cheers,
Tom Peste