[C#]StringWriter实现的一个功能
2007-11-13 09:25
309 查看
如何用一组双倍间距的句子创建一个连续的段落,然后将该段落重新转换为原来的文本:
using System;
using System.IO;
class StringRW
{
static void Main()
{
string textReaderText = "TextReader is the abstract base " +
"class of StreamReader and StringReader, which read " +
"characters from streams and strings, respectively.\n\n" +
"Create an instance of TextReader to open a text file " +
"for reading a specified range of characters, or to " +
"create a reader based on an existing stream.\n\n" +
"You can also use an instance of TextReader to read " +
"text from a custom backing store using the same " +
"APIs you would use for a string or a stream.\n\n";
Console.WriteLine("Original text:\n\n{0}", textReaderText);
string aLine, aParagraph = null;
StringReader strReader = new StringReader(textReaderText);
while(true)
{
aLine = strReader.ReadLine();
if(aLine != null)
{
aParagraph = aParagraph + aLine + " ";
}
else
{
aParagraph = aParagraph + "\n";
break;
}
}
Console.WriteLine("Modified text:\n\n{0}", aParagraph);
int intCharacter;
char convertedCharacter;
StringWriter strWriter = new StringWriter();
strReader = new StringReader(aParagraph);
while(true)
{
intCharacter = strReader.Read();
if(intCharacter == -1) break;
convertedCharacter = Convert.ToChar(intCharacter);
if(convertedCharacter == '.')
{
strWriter.Write(".\n\n");
strReader.Read();
strReader.Read();
}
else
{
strWriter.Write(convertedCharacter);
}
}
Console.WriteLine("\nOriginal text:\n\n{0}",
strWriter.ToString());
}
}
using System;
using System.IO;
class StringRW
{
static void Main()
{
string textReaderText = "TextReader is the abstract base " +
"class of StreamReader and StringReader, which read " +
"characters from streams and strings, respectively.\n\n" +
"Create an instance of TextReader to open a text file " +
"for reading a specified range of characters, or to " +
"create a reader based on an existing stream.\n\n" +
"You can also use an instance of TextReader to read " +
"text from a custom backing store using the same " +
"APIs you would use for a string or a stream.\n\n";
Console.WriteLine("Original text:\n\n{0}", textReaderText);
string aLine, aParagraph = null;
StringReader strReader = new StringReader(textReaderText);
while(true)
{
aLine = strReader.ReadLine();
if(aLine != null)
{
aParagraph = aParagraph + aLine + " ";
}
else
{
aParagraph = aParagraph + "\n";
break;
}
}
Console.WriteLine("Modified text:\n\n{0}", aParagraph);
int intCharacter;
char convertedCharacter;
StringWriter strWriter = new StringWriter();
strReader = new StringReader(aParagraph);
while(true)
{
intCharacter = strReader.Read();
if(intCharacter == -1) break;
convertedCharacter = Convert.ToChar(intCharacter);
if(convertedCharacter == '.')
{
strWriter.Write(".\n\n");
strReader.Read();
strReader.Read();
}
else
{
strWriter.Write(convertedCharacter);
}
}
Console.WriteLine("\nOriginal text:\n\n{0}",
strWriter.ToString());
}
}
相关文章推荐
- [C#]StringWriter实现的一个功能
- StringWriter实现的一个功能
- 用C#和vs2015编写了一个简单音乐播放器,实现功能,多条音乐导入,播放、暂停、上下曲。采用vs2105自带的一个播放器控件
- c#开发一个“记事本”程序,要求能够实现文件的新建、打开、编辑、保存功能
- 一个获取rgb的小程序,有兴趣的可以交流交流,好多地方还不够完美,不过功能可以实现(C# winForm)
- C#第十周任务之最后一项之创建一个如下的窗体,并在窗体上放置一个菜单、一个工具栏控件。菜单内容如第二个图所示。工具栏上有两个按钮,分别对应“打开文本文件”、“保存文本文件”。菜单和工具栏具体功能实现可
- C# 在主窗口中打开一个带有计算器功能的子窗口,有三种实现方法
- 开源一个C# Class实现Openfire登陆、推出、消息发送,方便其他系统集成IM功能了
- c#创建静态类,在其中定义一个泛型方法,实现查找数组元素的功能
- C#实现一个功能简单的web浏览器
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- Unity, C# ,TCP实现的一个简单的对话同步功能
- C# 实现简单打印(三)-认识打印控件,创建一个带打印功能的程序
- 开源一个C# Class实现Openfire登陆、推出、消息发送,方便其他系统集成IM功能了
- StringWriter实现的一个功能
- WPF学习——制作一个简单的录入界面(2):用C#编程实现所有控件的功能
- C# 实现一个注册机功能
- C#使用System.Timers.Timer类实现一个Button锁定功能(windows form)
- c# 实现一个在线电台的功能 急求.....
- Javascript实现一个简单的页面倒计时功能