StringWriter实现的一个功能

    如何用一组双倍间距的句子创建一个连续的段落,然后将该段落重新转换为原来的文本:

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 == -1break;
             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());
    }

}



posted on 2006-05-20 16:36 kim 阅读(330) 评论(0)  编辑 收藏 网摘 所属分类: C#编程


发表评论



姓名 [登录] [注册] 
主页
Email (仅博主可见) 
验证码 *  验证码看不清,换一张
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论   新用户注册   返回页首      

导航: 网站首页 社区 新闻 博问 闪存 网摘 招聘 .NET频道 知识库 找找看 Google站内搜索



China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
China-Pub 计算机绝版图书按需印刷服务

相关文章:

相关链接:
 

导航

统计

公告

中文: 罗江华
英文: KIM
职务: PL
工作地: 成都/新加坡/美国
MSN: ljhkim6@hotmail.com

---------------------------

我的微软MVP配置
我写/翻译的书



俱乐部:[cdproclub@gmail.com]
网站:http://www.cdpro.com.cn

与我联系

搜索

 

常用链接

留言簿

我参与的团队

随笔分类(202)

随笔档案(159)

文章分类(4)

文章档案(11)

相册

收藏夹(8)

创业

技术网站

我的好友

最新评论