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中文网其他相关文章!