熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

轉全角半角(C#,VB.NET)

2013-11-13 09:54:01  來源: .NET編程 

  /// 轉全角的函數(SBC case) /// 
      ///

  任意字符串

/// 全角字符串 ///
       ///全角空格為半角空格為 
      ///其他字符半角()與全角()的對應關系是均相差 ///

  public string ToSBC(string input)
{ //半角轉全角
    char[] c=inputToCharArray();
      for (int i = ; i < cLength; i++)
    {
       if (c[i]==)
    {
    c[i]=(char); continue;
  }
   if (c[i]<) c[i]=(char)(c[i]+);
   }
return new string(c);
}

///

/// 轉半角的函數(DBC case) ///
///

  任意字符串


/// 半角字符串 ///
///全角空格為半角空格為
///其他字符半角()與全角()的對應關系是均相差 ///

public string ToDBC(string input)
{
char[] c=inputToCharArray();
for (int i = ; i < cLength; i++)
{
if (c[i]==)
{
c[i]= (char); continue;
}
if (c[i]> && c[i]<)
c[i]=(char)(c[i]);
}
return new string(c);
}

  VB版本

  Public Function ToSBC()Function ToSBC(ByVal input As String) As String 轉全角 Dim c As Char() = inputToCharArray Dim i As Integer = While i < cLength If c(i) = ChrW() Then c(i) = ChrW() ElseIf AscW(c(i)) < Then c(i) = ChrW((AscW(c(i)) + )) End If SystemMathMin(SystemThreadingInterlockedIncrement(i) i ) End While Return New String(c) End Function Public Function ToDBC()Function ToDBC(ByVal input As String) As String 轉半角 Dim c As Char() = inputToCharArray Dim i As Integer = While i < cLength If AscW(c(i)) = Then c(i) = ChrW() ElseIf AscW(c(i)) > AndAlso AscW(c(i)) < Then c(i) = ChrW(AscW(c(i)) ) End If SystemMathMin(SystemThreadingInterlockedIncrement(i) i ) End While Return New String(c) End Function


From:http://tw.wingwit.com/Article/program/net/201311/11902.html
  • 上一篇文章:

  • 下一篇文章:
  • 相關文章
      没有相关文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.