本文介绍了Xe货币转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private double GetConvertedCurrencyValue(string inputCurrency, string outputCurrency, double value)
{
string request = String.Format("http://www.xe.com/ucc/convert.cgi?Amount={0}&From={1}&To={2}", value, inputCurrency, outputCurrency);
System.Net.WebClient wc = new System.Net.WebClient();
string apiResponse = wc.DownloadString(request); // This is a blocking operation.
wc.Dispose();
/* Formatting */
// Typical response: "XE.com: curr1 to curr2 rate: x curr1 = y curr2"
// The first part, up until "x curr1" is basically a constant
string header = String.Format("XE.com: {0} to {1} rate:", inputCurrency, outputCurrency);
// Removing the header
// The response now looks like this: x curr1 = y curr2
apiResponse = apiResponse.Replace(header, "");
// Let's split the response at '=', to retrieve the right part
string outValue = apiResponse.Split('=')[1];
// Getting rid of the 'curr2' part
outValue = outValue.Replace(outputCurrency, "");
return Double.Parse(outValue, System.Globalization.CultureInfo.InvariantCulture);
}
它给出了以下错误最后一行。请立即回复......
输入字符串的格式不正确。
it gives an below error in last line .please reply immediately......
Input string was not in a correct format.
推荐答案
string header = String.Format("XE.com: {0} to {2} rate:", inputCurrency, outputCurrency);
试试{1}
这是否足够直接?
try {1}
Is that immediate enough?
这篇关于Xe货币转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!