首先我用流读取一个txt的文件,文件内容如下:
0003B1CC,38,大家{换行}我?0003B1F4,92,三天...是在{换行}晚上吗?是,{换行}应该.我一行一行读取,然后使用正则表达式去掉数字以及英文,但是在遇到‘{’,“...”等标点符号后后面的不读取了。原因可能是match读取匹配汉字后遇到标点后面的就不读取了,求解决方法。
附上代码:
StreamReader sr = new StreamReader(txtpath.Text, System.Text.Encoding.GetEncoding("gb2312"));
string sLine = "";
string txt = "";
while (sLine != null)
{
sLine = sr.ReadLine();
string regexStr = "[\u4e00-\u9fa5]+";
Regex r = new Regex(regexStr, RegexOptions.None);
if (sLine != null)
{
Match mc = r.Match(sLine);
txt += mc.ToString();
}
}
sr.Close();
0003B1CC,38,大家{换行}我?0003B1F4,92,三天...是在{换行}晚上吗?是,{换行}应该.我一行一行读取,然后使用正则表达式去掉数字以及英文,但是在遇到‘{’,“...”等标点符号后后面的不读取了。原因可能是match读取匹配汉字后遇到标点后面的就不读取了,求解决方法。
附上代码:
StreamReader sr = new StreamReader(txtpath.Text, System.Text.Encoding.GetEncoding("gb2312"));
string sLine = "";
string txt = "";
while (sLine != null)
{
sLine = sr.ReadLine();
string regexStr = "[\u4e00-\u9fa5]+";
Regex r = new Regex(regexStr, RegexOptions.None);
if (sLine != null)
{
Match mc = r.Match(sLine);
txt += mc.ToString();
}
}
sr.Close();
解决方案 »
- 谁有winform窗体下,用OpenFileDialog选择文本文件,将内容显示到listview中的事例
- C#制作安装包的问题
- ORA-01426:数据溢出,寻求解决方案
- 各位给推荐本学习c#的好书,或者好的网站吧!
- 为什么无法更新oracle查询?老是返回第一次查询的结果
- 读取Oracle数据库的中文为乱码?
- 关于窗体显示退出
- C#编写的Com组件中可以调用Webservice吗
- 新手发问。(字符串型的值填到datetimepicker.text中)
- 请教一个动态定义变量问题~
- 大家帮我看看这段代码哪里出错了?
- 如何解决 c#中,socket编程中,客户端和服务器端,多次发送信息和随时接受信息?
if (sLine != null)
{
Match mc = r.Match(sLine);
while(mc.Success)
{
txt += mc.Value;
mc = mc.NextMatch();
}
}