Copy Code code as follows:
Class ExchangeRate
{
Private Const string _baseurl = "web address";
Public Const string CurrencyCode = "currency type with ' | ' Separate ";//currency type
Public Hashtable GetValues ()
{
Hashtable Htreturn = new Hashtable ();
string url = _baseurl; + Httputility.urlencode (tmset.tostring ("Yyyy/mm/dd", Datetimeformatinfo.invariantinfo));
WebClient WC = new WebClient ();
String sHtml = WC. downloadstring (URL);
String sXml = String. Empty;
int ivaluecnt = CurrencyCode. Split (new char[] {' | '}, stringsplitoptions.removeemptyentries). Length;
string[] Stbody = Shtml.split (new string[] {"<tbody>", "</tbody>"}, Stringsplitoptions.removeemptyentries );
foreach (String ss in Stbody)
{
if (ss. Contains ("Currency Name"))
{
string[] SBRs = ss. Split (new string[] {"</tr>"}, Stringsplitoptions.removeemptyentries);
foreach (String sbr in SBRs)
{
String scur = String. Empty;
Double drate = getcurrencyrate (SBR, out scur);
if (drate!= 0.0 &&!string. IsNullOrEmpty (Scur))
{
Htreturn.add (Scur, drate * 0.01);
if (Htreturn.count >= ivaluecnt)
Break
}
}
Break
}
}
return htreturn;
}
Private double Getcurrencyrate (string source, out string scurrency)
{
Scurrency = string. Empty;
String spattern = @ "<td.+?> (. +?) </td> ";
foreach (Match m in regex.matches (source, Spattern))
{
string ss = M.groups[1]. Value;
if (IsNumeric (ss))
Return double. Parse (ss);
Else
{
if (CurrencyCode. Contains (ss))
scurrency = ss. Trim ();
Else
Break
}
}
return 0.0;
}
public static bool IsNumeric (String str)
{
if (string. IsNullOrEmpty (str)) return false;
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex (@ "^[-]?\d+[.|,]?\d*$");
Return Reg. IsMatch (str);
}
}