【永恒的瞬間】
          ?Give me hapy ?
          **////?<summary>
          ????????
          ///?轉(zhuǎn)全角的函數(shù)(SBC?case)
          ????????
          ///?</summary>
          ????????
          ///?<param?name="input">任意字符串</param>
          ????????
          ///?<returns>全角字符串</returns>
          ????????
          ///<remarks>
          ????????
          ///全角空格為12288,半角空格為32
          ????????
          ///其他字符半角(33-126)與全角(65281-65374)的對(duì)應(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)的對(duì)應(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.C#中直接調(diào)用VB.NET的函數(shù),兼論半角與全角、簡(jiǎn)繁體中文互相轉(zhuǎn)化

          在C#項(xiàng)目中添加引用Microsoft.VisualBasic.dll, 可以在C#程序中直接使用VB.NET中豐富的函數(shù)

          ?1//?命令行編譯?:?csc?/r:Microsoft.VisualBasic.dll?Test.cs
          ?2
          ?3//?如果是用?Visual?Studio?.NET?IDE,?請(qǐng)按以下方法為項(xiàng)目添加引用:
          ?4//?打開[解決方案資源管理器],?右擊項(xiàng)目名稱,?選擇[添加引用],
          ?5//?從列表中選擇?Microsoft?Visual?Basic?.NET?Runtime?組件.
          ?6
          ?7using?Microsoft.VisualBasic;
          ?8
          ?9class?Test
          10{
          11??static?void?Main()
          12??{
          13????string?s?=?"博客園-空軍?[skyIV.cnBlogs.com]";
          14????System.Console.WriteLine(s);
          15????s?=?Strings.StrConv(s,?VbStrConv.Wide??????????????,?0);?//?半角轉(zhuǎn)全角
          16????s?=?Strings.StrConv(s,?VbStrConv.TraditionalChinese,?0);?//?簡(jiǎn)體轉(zhuǎn)繁體
          17????System.Console.WriteLine(s);
          18????s?=?Strings.StrConv(s,?VbStrConv.ProperCase????????,?0);?//?首字母大寫
          19????s?=?Strings.StrConv(s,?VbStrConv.Narrow????????????,?0);?//?全角轉(zhuǎn)半角
          20????s?=?Strings.StrConv(s,?VbStrConv.SimplifiedChinese?,?0);?//?繁體轉(zhuǎn)簡(jiǎn)體
          21????System.Console.WriteLine(s);
          posted on 2007-02-02 20:19 ???MengChuChen 閱讀(1825) 評(píng)論(0)  編輯  收藏 所屬分類: java_code
          主站蜘蛛池模板: 阿拉善左旗| 滕州市| 乌兰县| 民丰县| 区。| 屯昌县| 丹巴县| 吴堡县| 红桥区| 青海省| 米泉市| 新竹市| 昌邑市| 乌什县| 鄂尔多斯市| 洪湖市| 定陶县| 大埔县| 南汇区| 隆化县| 华宁县| 息烽县| 惠来县| 称多县| 区。| 张掖市| 新源县| 云浮市| 伊春市| 葵青区| 家居| 安康市| 通化市| 新沂市| 商水县| 连江县| 青田县| 阿巴嘎旗| 泾阳县| 怀安县| 金山区|