2013-05-04 49 views
-1

我有一個文本框包含我的餘額和另一個文本框,我想以歐元顯示餘額。當我點擊轉換按鈕時,我希望它能夠將英鎊兌換成歐元。如何將英鎊兌換成歐元?

那麼,如何讓我的餘額顯示在streling中,以及如何將它轉換爲歐元?

任何示例代碼將是偉大的,甚至直接我到一個網站,將教我這一點。

+3

什麼也沒有爲你工作,到目前爲止,什麼是您使用的貨幣匯率? – keyboardP 2013-05-04 11:58:15

+0

是的,這實際上只是一個通過webapi獲取匯率或者只是硬編碼的問題。 – Nomad101 2013-05-04 11:58:53

+2

這不是StackOverflow的工作原理。你必須嘗試自己做一些事情,當你遇到困難來到這裏並且詢問_specific_問題時。 – Leri 2013-05-04 11:59:28

回答

2

歐洲央行(ECB)提供了一個XML格式的每日貨幣匯率

鏈接,貨幣匯率是here

使用的WebRequest保存這個XML,寫你的包裝類做轉換

,如果你想使用xe.com使用此link,它有三個參數 1.amount轉換,2.貨幣和3貨幣

輸出鏈接的是

<wml> 
    <head> 
    <meta http-equiv="Cache-Control" content="must-revalidate" forua="true"/> 
    <meta http-equiv="Cache-Control" content="no-cache" forua="true"/> 
    </head> 
    <card title="XE Converter"> 
    <p mode="wrap" align="center"> 
    XE Converter 
    </p> 
    <p mode="nowrap" align="left">100 SGD =</p> 
    <p mode="wrap" align="right">18,287.95 HUF</p> 
    <p mode="wrap" align="center"> 
    Live @ 12:07 GMT 
    </p> 
    <p mode="nowrap" align="left"> 
    <a href="step1.wml">Another?</a><br/> 
    <a href="http://www.xe.com/wap/index.wml">XE Home</a> 
    </p> 
    </card> 
    </wml> 

再次使用WebRequest類和得到的輸出和解析XML

樣品是在這裏

HttpWebRequest myHttpWebRequest = null;  //Declare an HTTP-specific implementation of the WebRequest class. 
     HttpWebResponse myHttpWebResponse = null; //Declare an HTTP-specific implementation of the WebResponse class 
     XmlDocument myXMLDocument = null;   //Declare XMLResponse document 
     XmlTextReader myXMLReader = null;   //Declare XMLReader 

     try 
     { 
      //Create Request 
      myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.xe.com/wap/2co/convert.cgi?Amount=100&From=SGD&To=HUF"); 
      myHttpWebRequest.Method = "GET"; 
      myHttpWebRequest.ContentType = "text/xml; encoding='utf-8'"; 

      //Get Response 
      myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 

      //Now load the XML Document 
      myXMLDocument = new XmlDocument(); 

      //Load response stream into XMLReader 
      myXMLReader = new XmlTextReader(myHttpWebResponse.GetResponseStream()); 
      myXMLDocument.Load(myXMLReader); 
     } 
     catch (Exception myException) 
     { 
      throw myException; 
     } 
     finally 
     { 
      myHttpWebRequest = null; 
      myHttpWebResponse = null; 
      myXMLReader = null; 
     } 
相關問題