StringWriter实现的一个功能
2010-03-29 10:40
302 查看
原文地址:http://www.dingos.cn/index.php?topic=1794.0
如何用一组双倍间距的句子创建一个连续的段落,然后将该段落重新转换为原来的文本:
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实现的一个功能
- [C#]StringWriter实现的一个功能
- StringWriter实现的一个功能
- [置顶] Android开发之清除缓存功能实现方法,可以集成在自己的app中,增加一个新功能。
- 实现一个特殊的栈,在实现栈的基本功能的基础上,再实现返回栈中最小元素的操作。
- 实现将student中的所有信息在一个模板页上显示,格式参考课件中的图片。并实现编辑功能。
- javascript实现的一个信息提示的小功能/
- 一个简单的例子看明白如何利用window.location.hash实现ajax操作时浏览器的前进/后退功能
- 批量处理 Html img 标签,给 img 标签包裹一个 <a href="${url}"> 标签,用来实现“查看大图”的功能
- 一个函数5行代码即可实现完整的面向方面AOP编程功能
- jquery实现的一个提前搜索功能
- 一个iOS图片选择器的DEMO(实现图片添加,宫格排列,图片长按删除,以及图片替换等功能)
- 最近实现的一个分离文章内容功能,挺有意思,分享一下
- 模块:js实现一个倒计时功能
- 实现一个具有文件下载功能的网页
- 一个比较实用的sql实现代码功能
- 利用字符重复出现的次数,编写一个方法,实现基本的字符串压缩功能。比如,字符串“aabcccccaaa”经压缩会变成“a2b1c5a3”。若压缩后的字符串没有变短,则返回原先的字符串。
- 另外一个ASP.NET 实现邮件发送和接受的功能(Sockets)
- 创建一个数组实现一些功能
- Android网络编程之一个Android下菜单系统模块的实现(客户端—结算功能)