chiname

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
三种常用的字符串判空串方法:
  • Length法:bool isEmpty = (str.Length == 0);
  • Empty法:bool isEmpty = (str == String.Empty);
  • General法:bool isEmpty = (str == "");

实践证明用Length方法判空是最快的(在32位系统上,System.Int32运算最快了),注意只有字符串不为null的前提下,.NET才会进一步计算s.Length是否为0,所以一般常用 if( (s == null) || (s.Length == 0) ) 进行判断。

posted on 2004-12-03 10:14  把我的欢乐带给你  阅读(4759)  评论(2编辑  收藏  举报