VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • 汉字首字母拼音码(vb.net & csharp)

CSharp

public string GetPinYin(string text)
        {
            
char
 pinyin;
            
byte
[] array;
            System.Text.StringBuilder sb 
= new
 System.Text.StringBuilder(text.Length); 
            
foreach(char c in
 text)
            {
                pinyin 
=
 c;
                array 
= System.Text.Encoding.Default.GetBytes(new char
[]{c});

                
if(array.Length == 2
)
                {
                    
int i = array[0* 0x100 + array[1
];

                    
if(i < 0xB0A1) pinyin = c; else

                        if(i < 0xB0C5) pinyin = 'a'else
                        if(i < 0xB2C1) pinyin = 'b'else
                        if(i < 0xB4EE) pinyin = 'c'else
                        if(i < 0xB6EA) pinyin = 'd'else
                        if(i < 0xB7A2) pinyin = 'e'else
                        if(i < 0xB8C1) pinyin = 'f'else
                        if(i < 0xB9FE) pinyin = 'g'else
                        if(i < 0xBBF7) pinyin = 'h'else
                        if(i < 0xBFA6) pinyin = 'g'else
                        if(i < 0xC0AC) pinyin = 'k'else
                        if(i < 0xC2E8) pinyin = 'l'else
                        if(i < 0xC4C3) pinyin = 'm'else
                        if(i < 0xC5B6) pinyin = 'n'else
                        if(i < 0xC5BE) pinyin = 'o'else
                        if(i < 0xC6DA) pinyin = 'p'else
                        if(i < 0xC8BB) pinyin = 'q'else
                        if(i < 0xC8F6) pinyin = 'r'else
                        if(i < 0xCBFA) pinyin = 's'else
                        if(i < 0xCDDA) pinyin = 't'else
                        if(i < 0xCEF4) pinyin = 'w'else
                        if(i < 0xD1B9) pinyin = 'x'else
                        if(i < 0xD4D1) pinyin = 'y'else
                        if(i < 0xD7FA) pinyin = 'z';
                }

                sb.Append(pinyin);
            }

            
return
 sb.ToString();
        }

vb.net
  Public Function GetPinYin(ByVal str As StringAs String
        Dim pinyin As Char
        Dim c As Char
        Dim array() As Byte
        Dim i As Integer
        Dim sb As New System.Text.StringBuilder(str.Length)
        
For Each c In str
.ToCharArray
            pinyin 
=
 c
            array 
= System.Text.Encoding.Default.GetBytes(New Char
() {c})
            
If array.Length = 2 Then

                i = array(0* &H100 + array(1)
                
If i < &HB0A1 Then

                    pinyin = c
                
ElseIf i < &HB0C5 Then

                    pinyin = "a"
                ElseIf i < &HB2C1 Then
                    pinyin = "b"
                ElseIf i < &HB4EE Then
                    pinyin = "c"
                ElseIf i < &HB6EA Then
                    pinyin = "d"
                ElseIf i < &HB7A2 Then
                    pinyin = "e"
                ElseIf i < &HB8C1 Then
                    pinyin = "f"
                ElseIf i < &HB9FE Then
                    pinyin = "g"
                ElseIf i < &HBBF7 Then
                    pinyin = "h"
                ElseIf i < &HBFA6 Then
                    pinyin = "g"
                ElseIf i < &HC0AC Then
                    pinyin = "k"
                ElseIf i < &HC2E8 Then
                    pinyin = "l"
                ElseIf i < &HC4C3 Then
                    pinyin = "m"
                ElseIf i < &HC5B6 Then
                    pinyin = "n"
                ElseIf i < &HC5BE Then
                    pinyin = "o"
                ElseIf i < &HC6DA Then
                    pinyin = "p"
                ElseIf i < &HC8BB Then
                    pinyin = "q"
                ElseIf i < &HC8F6 Then
                    pinyin = "r"
                ElseIf i < &HCBFA Then
                    pinyin = "s"
                ElseIf i < &HCDDA Then
                    pinyin = "t"
                ElseIf i < &HCEF4 Then
                    pinyin = "w"
                ElseIf i < &HD1B9 Then
                    pinyin = "x"
                ElseIf i < &HD4D1 Then
                    pinyin = "y"
                ElseIf i < &HD7FA Then
                    pinyin = "z"
                End If
            End If
            sb.Append(pinyin)
        
Next
        Return sb.ToString()
    
End Function
 
 

相关教程