富贵资源网 Design By www.hznty.com
复制代码 代码如下:
class ExchangeRate
{
private const string _BASEURL = "网页地址";
public const string CURRENCYCODE = "货币类型以'|'隔开";//货币类型
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[] { '|' }, 10, 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);
}
}
class ExchangeRate
{
private const string _BASEURL = "网页地址";
public const string CURRENCYCODE = "货币类型以'|'隔开";//货币类型
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[] { '|' }, 10, 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);
}
}
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...