小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

全角與半角,簡體與繁體之間的轉(zhuǎn)換C#

 pengx 2008-09-27

1.

/// <summary>
/// 轉(zhuǎn)全角的函數(shù)(SBC case)
/// </summary>
/// <param name="input">任意字符串</param>
/// <returns>全角字符串</returns>
///<remarks>
///全角空格為12288,半角空格為32
///其他字符半角(33-126)與全角(65281-65374)的對應(yīng)關(guān)系是:均相差65248
///</remarks>        
public string ToSBC(string input)
{
    
//半角轉(zhuǎn)全角:
    char[] c = input.ToCharArray();
    
for (int i = 0; i < c.Length; i++)
    {
    
if (c[i] == 32)
    {
        c[i] 
= (char)12288;
        
continue;
    }
    
if (c[i] < 127)
        c[i] 
= (char)(c[i] + 65248);
    }
    
return new string(c);
}


/**/
/// <summary>
/// 轉(zhuǎn)半角的函數(shù)(DBC case)
/// </summary>
/// <param name="input">任意字符串</param>
/// <returns>半角字符串</returns>
///<remarks>
///全角空格為12288,半角空格為32
///其他字符半角(33-126)與全角(65281-65374)的對應(yīng)關(guān)系是:均相差65248
///</remarks>
public string ToDBC(string input)
{
    
char[] c = input.ToCharArray();
    
for (int i = 0; i < c.Length; i++)
    {
    
if (c[i] == 12288)
    {
        c[i] 
= (char)32;
        
continue;
    }
    
if (c[i] > 65280 && c[i] < 65375)
        c[i] 
= (char)(c[i] - 65248);
    }
    
return new string(c);
}



2.使用Microsoft.VisualBasic類庫
在C#項目中添加引用Microsoft.VisualBasic.dll, 可以在C#程序中直接使用VB.NET中豐富的函數(shù)  1// 命令行編譯 : csc /r:Microsoft.VisualBasic.dll Test.cs

// 如果是用 Visual Studio .NET IDE, 請按以下方法為項目添加引用:
// 打開[解決方案資源管理器], 右擊項目名稱, 選擇[添加引用],
// 從列表中選擇 Microsoft Visual Basic .NET Runtime 組件.

using Microsoft.VisualBasic;

class Test
{
  
static void Main()
  {
    
string s = "博客園-空軍 [skyIV.cnBlogs.com]";
    System.Console.WriteLine(s);
    s 
= Strings.StrConv(s, VbStrConv.Wide              , 0); // 半角轉(zhuǎn)全角
    s = Strings.StrConv(s, VbStrConv.TraditionalChinese, 0); // 簡體轉(zhuǎn)繁體
    System.Console.WriteLine(s);
    s 
= Strings.StrConv(s, VbStrConv.ProperCase        , 0); // 首字母大寫
    s = Strings.StrConv(s, VbStrConv.Narrow            , 0); // 全角轉(zhuǎn)半角
    s = Strings.StrConv(s, VbStrConv.SimplifiedChinese , 0); // 繁體轉(zhuǎn)簡體
    System.Console.WriteLine(s);
  }
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多