StringReader 和 StringWriter 衍生自 TextReader 和 TextWriter
StringWriter 用於寫入字串緩衝區。它實作了一個 TextWriter,用於將資訊寫入字串。
對於 StringWriter -
StringWriter sWriter = new StringWriter(); while(true) { myChar = strReader.Read(); if(myChar == -1) break; convertedChar = Convert.ToChar(myChar); if(convertedChar == '.') { strWriter.Write("."); sReader.Read(); sReader.Read(); }else { sWriter.Write(convertedChar); } } }
StringReader 讀取字串 -
StringBuilder sbuilder = new StringBuilder(); // append sbuilder.AppendLine("Line one characters"); sbuilder.AppendLine("Line two characters"); sbuilder.AppendLine("Line three characters"); // read string using (StringReader sReader = new StringReader(sbuilder.ToString())) { string readString = await sReader.ReadToEndAsync(); Console.WriteLine(readString); }
以上是C# 中的 StringWriter 與 StringReader?的詳細內容。更多資訊請關注PHP中文網其他相關文章!