2010-11-01 85 views

回答

1

不是直接的,而是存在着需要StreamReader,所以你可以做這樣的事情的ImportFile超負荷:如果你有內容的字節數組

  • byte[] contentBytes = ... 
    QifDom qifDom; 
    using (Stream stream = new MemoryStream(contentBytes)) 
    using (StreamReader reader = new StreamReader(stream)) 
    { 
        qifDom = QifDom.ImportFile(); 
    } 
    
  • 如果您的內容爲字符串:

    string content = ... 
    byte[] contentBytes = Encoding.UTF8.GetBytes(content); 
    QifDom qifDom; 
    using (Stream stream = new MemoryStream(contentBytes)) 
    using (StreamReader reader = new StreamReader(stream)) 
    { 
        qifDom = QifDom.ImportFile(); 
    } 
    

(壞API的設計,順便...參數應該是TextReader,不StreamReader,所以我們可以使用一個StringReader而不是轉換字符串字節)

另外,還要注意的例子在主頁上是不正確的(沒有QifDom.Import財產)

+0

哪一個是最好的,二進制或字符串輸入? – 001 2010-11-01 03:57:31

+0

http://en.wikipedia.org/wiki/Quicken_Interchange_Format http://web.intuit.com/support/quicken/docs/d_qif.html(根據QIF規範,不使用特殊字符) – 001 2010-11-01 03:58:26