1、半角转全角
1c = "hello World".ToCharArray();
2 for(int i = 0; i < c.Length; i++)
3 {
4 byte[] b = System.Text.Encoding.Unicode.GetBytes(c,i,1);
5 if(b.Length == 2)
6 {
7 if(b[1] == 0)
8 {
9 b[0]=(byte)(b[0]-32);
10 b[1]=255;
11 c[i]=System.Text.Encoding.Unicode.GetChars(b)[0];
12 }
13 }
14 }
15 string strNew=new string(c);
16
2 for(int i = 0; i < c.Length; i++)
3 {
4 byte[] b = System.Text.Encoding.Unicode.GetBytes(c,i,1);
5 if(b.Length == 2)
6 {
7 if(b[1] == 0)
8 {
9 b[0]=(byte)(b[0]-32);
10 b[1]=255;
11 c[i]=System.Text.Encoding.Unicode.GetChars(b)[0];
12 }
13 }
14 }
15 string strNew=new string(c);
16
2、全角转半角
1string QJstr = "hello,Amigo quanjiao字符";
2 char[] c = QJstr.ToCharArray();
3 for(int i = 0; i < c.Length; i++)
4 {
5 byte[] b = System.Text.Encoding.Unicode.GetBytes(c,i,1);
6 if(b.Length == 2)
7 {
8 if(b[1] == 255)
9 {
10 b[0] =(byte)(b[0]+32);
11 b[1] = 0;
12 c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
13 }
14 }
15 }
16 string strNew=new string(c);
2 char[] c = QJstr.ToCharArray();
3 for(int i = 0; i < c.Length; i++)
4 {
5 byte[] b = System.Text.Encoding.Unicode.GetBytes(c,i,1);
6 if(b.Length == 2)
7 {
8 if(b[1] == 255)
9 {
10 b[0] =(byte)(b[0]+32);
11 b[1] = 0;
12 c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
13 }
14 }
15 }
16 string strNew=new string(c);
3、其他方法
1 半全角互换
57
57
转:http://www.haoyu63.com/article.asp?id=33