随笔 - 68  文章 - 2 评论 - 93 trackbacks - 3
<2004年5月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345



MSN:xleelee@msn.com

如果想飞得高
就应该把地平线忘掉

昵称:hi-justin
园龄:7年8个月
粉丝:0
关注:0

搜索

 
 

常用链接

随笔分类

随笔档案

文章分类

文章档案

相册

My friends

Resource list

积分与排名

  • 积分 - 68325
  • 排名 - 1538

最新评论

阅读排行榜

评论排行榜

推荐排行榜

//获得汉字的区位码
  byte[] array = new byte[2];
  array = System.Text.Encoding.Default.GetBytes("啊");


int i1 = (short)(array[0] - ''\0'');
  int i2 = (short)(array[1] - ''\0'');


//unicode解码方式下的汉字码
  array = System.Text.Encoding.Unicode.GetBytes("啊");
  i1 = (short)(array[0] - ''\0'');
  i2 = (short)(array[1] - ''\0'');


//unicode反解码为汉字
  string str = "4a55";
  string s1 = str.Substring(0,2);
  string s2 = str.Substring(2,2);


int t1 = Convert.ToInt32(s1,16);
  int t2 = Convert.ToInt32(s2,16);


array[0] = (byte)t1;
  array[1] = (byte)t2;


string s = System.Text.Encoding.Unicode.GetString(array);


//default方式反解码为汉字
  array[0] = (byte)196;
  array[1] = (byte)207;
  s = System.Text.Encoding.Default.GetString(array);


//取字符串长度
  s = "woshi蓝蓝";
  int len = s.Length;//will output as 6
  byte[] sarr = System.Text.Encoding.Default.GetBytes(s);
  len = sarr.Length;//will output as 3+3*2=9


//字符串相加
  System.Text.StringBuilder sb = new System.Text.StringBuilder("");
  sb.Append("i ");
  sb.Append("am ");
  sb.Append("蓝蓝");

/////////////////////////////////////////////////////////////////////

补充:

string --> byte array

byte[] data=Syste.Text.Encoding.ASCII.GetBytes(string);

string --> byte

byte data = Convert.ToByte(string);

byte[]-->string

string string = Encoding.ASCII.GetString( bytes, 0, nBytesSize );

posted on 2004-05-26 22:39 hi-justin 阅读(4458) 评论(3) 编辑 收藏

FeedBack:
#1楼 2005-03-13 11:10 liu
我按照上面获得区位码的方法做,结果报错了

我后来是这么做,不知道对不对
//获得汉字的区位码
  byte[] array = new byte[2];
  array = System.Text.Encoding.Default.GetBytes("啊");
int[] i=new int[2];


i[0] = (short)(array[0] - 160);
  i[1]= (short)(array[1] - 160);

 回复 引用   
#2楼 2005-11-05 11:30 1111[未注册用户]
哪个晓得将字符串倒装???????????????????????
 回复 引用