首页 > 开发 > 综合 > 正文

C#中生成中文繁体web页面

2020-02-03 13:42:18
字体:
来源:转载
供稿:网友


c#中生成中文繁体web页面



1 在工程中引用microsoft.visualbasic.dll

一般此文件在.net框架环境目录中如c:/ winnt /microsoft.net /framework /v1.1.4322

/microsoft.visualbasic.dll。



2 使用方法

microsoft.visualbasic.strings.strconv( “instr”,microsoft.visualbasic.vbstrconv.traditionalchinese, system.globalization.cultureinfo.currentculture.lcid);

* 该方法的使用可以在msdn中找到。

3 生成web页面使用编码 950,代码如下:

//写文件

public bool writefile( string contentstr,string filepath )

{

try

{

if ( filepath == null)

return false;

this.createdir( filepath.substring( 0,filepath.lastindexof( "//" ) ) );

streamwriter outstream = new streamwriter( filepath,false,system.text.encoding.getencoding( 950 ) );

outstream.write( contentstr );

outstream.close();

return true;

}

catch

{

return false;

}

}



4 读简体文件时使用编码 936

//读文件

public string readfile( string filepath )

{

string restr = "";

if ( filepath ==null ) return restr;

using ( streamreader sr = new streamreader( filepath,system.text.encoding.getencoding( 936 ) ) )

{

string line;

while( (line = sr.readline())!=null )

{

restr += line+"/r/n";

}

}

return restr;

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表