程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> C#中生成中文繁體web頁面

C#中生成中文繁體web頁面

編輯:關於C#
 

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;

}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved