码迷,mamicode.com
首页 > 编程语言 > 详细

Java 获取字符长度

时间:2014-11-27 10:33:19      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   color   sp   java   for   div   log   

 1 /**
 2      * 
 3      * @param 字符串
 4      * @return 字符长度
 5      */
 6     public int getWordCount(String str) {
 7         int length = 0;
 8         for (int i = 0; i < str.length(); i++) {
 9             int ascii = Character.codePointAt(str, i);
10             if (ascii >= 0 && ascii <= 255) {
11                 length++;
12             } else {
13                 length += 2;
14             }
15         }
16         return length;
17     }

 

Java 获取字符长度

标签:style   blog   ar   color   sp   java   for   div   log   

原文地址:http://www.cnblogs.com/leichentao0905/p/4125686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!