asp.net C#读取中文字符代码

asp教程.net c#读取中文字符代码

private static void fnfileprocess()
{
streamreader reader = new streamreader(@"d:1500.txt", encoding.getencoding("gb2312"));
streamwriter writeren = new streamwriter(@"d:english.txt", false, encoding.utf8, 1024);
streamwriter writerch = new streamwriter(@"d:chinese.txt", false, encoding.utf8, 1024);
try
{
int i = 1;
for (string line = reader.readline(); line != null; line = reader.readline())
{
if (i % 2 == 1)
{
writeren.writeline(line);
}
else
{
writerch.writeline(line);
}
i++;
}
console.writeline(i + "tok");
}
catch (exception ex)
{
console.writeline(ex.tostring());
}
finally
{
//不清空缓冲区,得到的文件总是少几十行
writeren.flush();
writerch.flush();
}
}

时间: 2024-08-02 01:58:29

asp.net C#读取中文字符代码的相关文章

ASP 判断是否有中文的代码_应用技巧

在 ASP(VBScript 为语言)中,Asc 函数的返回值小于 0 的,可以被判断为中文字符.Asc 函数返回与字符串的第一个字母对应的 ANSI 字符代码. 复制代码 代码如下: '判断字符串中是否有中文字符 '有-返回 true '无-返回 false '这里的中文字符可能还包括日文.韩文等东方文字 function HasChinese(str) HasChinese = false dim i for i=1 to Len(str) if Asc(Mid(str,i,1)) < 0

asp.net C# 读取Excel数据代码

asp教程.net  c# 读取excel数据代码 public dataset exceltods(string path)     {        string con = "provider=microsoft.jet.oledb.4.0;data source="+"e:\collegemis\upexcel\" + fileupload1.filename+";extended properties='excel 8.0;imex=1'&quo

asp检测是否为中文字符函数_应用技巧

<% '****************************** '函数:CheckChinese(strng) '参数:strng,待验证字符 '描述:检测是否为中文字符,返回值:中文为true,否则false '示例:<%=CheckChinese(strng)%> '****************************** Function CheckChinese(strng) CheckChinese = true Dim regEx, Match Set regEx

asp检测是否为中文字符函数

<% '****************************** '函数:CheckChinese(strng) '参数:strng,待验证字符 '描述:检测是否为中文字符,返回值:中文为true,否则false '示例:<%=CheckChinese(strng)%> '****************************** Function CheckChinese(strng) CheckChinese = true Dim regEx, Match Set regEx

C#读取中文字符及清空缓冲区的实现代码

开时始,得到的中文文件中的字符是乱码的,鸟符号看的头晕.于是就细究streamreader读取的编码格式,默认的编码是ascii,单字节的,就尝试utf8,乱码:尝试gb2312,OK! 可另一个问题又出现了,得到的两个文件的行数都不到1500行,尝试N次还是不行,很郁闷.google了下,看到try catch,就想到释放缓冲区,结果很HAPPY! 复制代码 代码如下: private static void FnFileProcess() { StreamReader reader = ne

Android中读取中文字符的文件与文件读取相关介绍_Android

一.如何显示assets/license.txt(中文)的内容? (1)方法1:InputStream.available()得到字节数,然后一次读取完. 复制代码 代码如下: private String readUserAgreementFromAsset(String assetName) { String content =""; try { InputStream is= getAssets().open(assetName); if (is != null){ DataIn

Android中读取中文字符的文件与文件读取相关介绍

一.如何显示assets/license.txt(中文)的内容? (1)方法1:InputStream.available()得到字节数,然后一次读取完. 复制代码 代码如下: private String readUserAgreementFromAsset(String assetName) { String content =""; try { InputStream is= getAssets().open(assetName); if (is != null){ DataIn

PHP解码unicode编码的中文字符代码分享_php实例

问题背景: 晚上在抓取某网站数据,结果在数据包中发现了这么一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,我现在就是想解码出中文来,上度娘搞了半天,试了很多的姿(方)势(法),终于搞定了. 解决方案: 呵呵,老外就是给力啊, 猛戳这里看老外给的解决方案 方案A(稳定版+推荐): function replace_unicode_escape_sequence($match) { return m

ASP使用FSO读取模板的代码

m_Root是文件名,可以使用相对路径. 调用调用示例: Response.Write(LoadFile("Test.htm")) Function LoadFile(m_Root) Dim Filename,fso,hndFile Filename = m_Root If Right(Filename, 1)<>"/" And Right(Filename, 1)<>"\" Then Filename = Filenam