惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
B
Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Proofpoint News Feed
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
博客园 - 叶小钗
S
SegmentFault 最新的问题
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
腾讯CDC
博客园 - Franky
博客园 - 聂微东
V
Visual Studio Blog
GbyAI
GbyAI
Martin Fowler
Martin Fowler
罗磊的独立博客
Y
Y Combinator Blog

博客园 - 阿伟

转一个哥们的日记看了让你吐血 IT技术和职位小览和应聘注意事项 生活中的笑话 男人25岁前的忠告(转) 经典承诺 怎样对待男人和女人之间关系 插入排序(C#) 快速排序(c#) 如何关闭常见端口(113、4899、389、6129等端口) 选择排序(C#) C#常用函数 几个网络术语!~ net命令研究 股票术语集锦 找女朋友的标准,男人不看后悔一辈子!!! DataGrid自定义分页存储过程 男生给女生最牛B的告白 一个光棍的呐喊! 令人呕吐的几则笑话^_^
一些字符串操作的常用用法 - 阿伟 - 博客园
阿伟 · 2006-03-01 · via 博客园 - 阿伟

一些字符串操作的常用用法

//获得汉字的区位码
  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 = "iam方枪枪";
  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("方枪枪");

posted on 2006-03-01 17:41  阿伟  阅读(285)  评论()    收藏  举报