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

推荐订阅源

T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
量子位
Martin Fowler
Martin Fowler
月光博客
月光博客
P
Proofpoint News Feed
博客园_首页
Y
Y Combinator Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
H
Help Net Security
U
Unit 42
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 荷梅月剑

分布式应用(Distributed Application) ActiveReports:打印参数设置 ActiveReports 按组分页 在ActiveReport中显示页码 eclipse显示行数 JAVA延时 - 荷梅月剑 - 博客园 初学Java多线程:线程的生命周期 java多线程例子 Api函数声明的格式 - 荷梅月剑 - 博客园 说实话,我更喜欢当一个程序员 Rational Rose 2003 下载及破解方法 不可替代性 爱的链条,让人有所启发的故事 上学与不上学的区别(奇文共赏) jQuery获得各种控件Value的方法 Lc.exe已退出,代码为-1 的解决方法 使用UNIQUEIDENTIFIER做为主键 返回值的解决方法 EasyUi tabs的高度与宽度何根据IE窗口的变化自适应 - 荷梅月剑 - 博客园 再回博客园
计算出中文字串的实际长度
荷梅月剑 · 2007-12-06 · via 博客园 - 荷梅月剑

计算出中文字串的实际长度

Posted on 2007-12-06 13:51  荷梅月剑  阅读(214)  评论()    收藏  举报

private int strlen(string arg_strSource)
{
    int intStringLength = 0; //字串實際長度
    if(arg_strSource.Length > 1)
    {
        System.Text.ASCIIEncoding objAscII = new System.Text.ASCIIEncoding();
        byte[] ary_bteStringBuffer = objAscII.GetBytes(arg_strSource);
        for (int i=0 ; i <= ary_bteStringBuffer.Length-1 ; i++)
        {
            if (ary_bteStringBuffer[i] == 63) //判斷是否為中文字或全型符號
            {
                intStringLength++;
            }
            intStringLength++;
        }
    }    
    return intStringLength;
}