当前位置:首页 > C#中生成中文繁体web页面

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

点击次数:1168  更新日期:2010-12-28
\n

1 在工程中引用Microsoft.VisualBasic.dll


\n

一般此文件在.net框架环境目录中如C:\\ WINNT \\Microsoft.NET \\Framework \\v1.1.4322


\n

\\Microsoft.VisualBasic.dll。


\n


\n

2 使用方法


\n

Microsoft.VisualBasic.Strings.StrConv( “instr”,Microsoft.VisualBasic.VbStrConv.TraditionalChinese, System.Globalization.CultureInfo.CurrentCulture.LCID);


\n

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


\n

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


\n

//写文件


\n

public bool WriteFile( string contentStr,string filepath )


\n

{


\n

try


\n

{


\n

if ( filepath == null)


\n

return false;


\n

this.CreateDir( filepath.Substring( 0,filepath.LastIndexOf( “\\\\” ) ) );


\n

StreamWriter outStream = new StreamWriter( filepath,false,System.Text.Encoding.GetEncoding( 950 ) );


\n

outStream.Write( contentStr );


\n

outStream.Close();


\n

return true;


\n

}


\n

catch


\n

{


\n

return false;


\n

}


\n

}


\n


\n

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


\n

//读文件


\n

public string ReadFile( string filepath )


\n

{


\n

string reStr = “”;


\n

if ( filepath ==null ) return reStr;


\n

using ( StreamReader sr = new StreamReader( filepath,System.Text.Encoding.GetEncoding( 936 ) ) )


\n

{


\n

string line;


\n

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


\n

{


\n

reStr += line+”\\r\\n”;


\n

}


\n

}


\n

return reStr;


\n

}


\n

来源:http://blog.csdn.net/21aspnet

\n