月耳思进

人生在世如身处荆棘之中,心不动,人不妄动,不动则不伤;如心动则人妄动,伤其身痛其骨,于是体会到世间诸般痛苦。
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

[转][小技巧]计算字符串的长度

Posted on 2006-01-22 20:59  Xfan  阅读(167)  评论(0编辑  收藏  举报
/**//// <summary>
        
/// 计算字符串的长度(一个汉字算两个字符)
        
/// </summary>
        
/// <param name="Str">要计算的字符串</param>
        
/// <returns>该字符串的长度</returns>

        public static int strLen( string Str )
        
{
            
try
            
{
                
byte[] s = System.Text.Encoding.Default.GetBytes( Str );
                
return s.Length;
            }

            
catch
            
{
                
return 0;
            }

        }
来自 翱翔.Net Blog Http://cnblogs.com/Hover