2011-01-14 24 views
1

我需要了解更多關於串流技術。 我正在使用biztalk並希望開發一些自定義管道組件。 對於性能因素,一切都必須以流爲基礎。 我收到一個消息流,但我想做一些替代文本, 我現在要做的是:串流編程

string msg = ""; 
using(StreamReader r = new StreamReader(stream)){ 
    msg = r.readToEnd(); 
} 

//do replacements 

//send stream away 
StreamWriter... 

正如你看到我打破流當我執行r.readToEnd()。 如何編輯流中的消息?

THX

回答

4

你不能。您可以從流中讀取部分消息,在每個部分中替換您想要的內容,並最終將處理後的部分寫入另一個流。

使用ReadToEnd與流式概念相反。我可以建議你應該使用:

using (StreamReader r = new StreamReader(stream)) 
using (StreamWriter w = new StreamWriter(someOutputStream)) 
{ 
    string line = null; 
    while ((line = r.ReadLine()) != null) 
    { 
     line = DoReplacements(line); 
     w.WriteLine(line); 
    } 
} 
+0

好的,thx爲你的幫助:) – 2011-01-14 13:33:45