<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    大大毛 的筆記

      DDM's Note

    哪怕沒有辦法一定有說法,
    就算沒有鴿子一定有烏鴉,
    固執無罪 夢想有價,
    讓他們驚訝.

    posts - 14, comments - 23, trackbacks - 0, articles - 58
       :: 首頁 ::  :: 聯系 ::  :: 管理

    統計中英文字數的簡單方法

    Posted on 2006-04-17 00:33 大大毛 閱讀(2224) 評論(1)  編輯  收藏 所屬分類: JAVA
    ??? 翻了翻以前積累下的一些資料,看到其中有一個統計中英文字符數的例子,很簡單,感覺也比較有意思,一直以來都沒有這么去想過問題,現在把它記下來。
    import ?java.io. * ;

    public ? class ?Test?
    {
    ????
    /**
    ?????*?統計字串中中文字符數量
    ?????*?
    @param ?str:GB編碼字符串
    ?????
    */

    ????
    public ? static ? int ?statGBCharCount1(String?str)? {
    ????????
    int ?GBCount? = ? - 1
    ;
    ????????String?otherStr?
    = ? null
    ;
    ????????
    ????????
    try
    {
    ????????????otherStr?
    = ? new ?String(str.getBytes(), " ISO8859_1 "
    );
    ????????????GBCount?
    = ?otherStr.length()? -
    ?str.length();
    ????????}
    catch (UnsupportedEncodingException?ex) {
    ????????????
    throw ? new ?RuntimeException( " UnsupportedEncodingException "
    );
    ????????}

    ????????
    ????????
    return ?GBCount;
    ????}

    ????
    /**
    ?????*?統計字串中中文字符數量
    ?????
    */

    ????
    public ? static ? int ?statGBCharCount2(String?str)? {
    ????????
    int ?GBCount? = ? - 1
    ;
    ????????
    ????????GBCount?
    = ?str.replaceAll( " [\u0000-\u0127] " , ""
    ).length();
    ????????System.out.println(
    " asc字符: " ? + ?str.replaceAll( " [\u0000-\u0127] " , ""
    ));
    ????????System.out.println(
    " 非asc字符: " ? + ?str.replaceAll( " [^\u0000-\u0127] " , ""
    ));
    ????????
    ????????
    return
    ?GBCount;
    ????}

    ????
    ????
    public ? static ? void ?main(String[]?args)? {
    ????????String?str?
    = ? " This?is?test?string?這是一個測試字符串 "
    ;
    ????????System.out.println(
    " 中文字符數: " +
    ?Test.statGBCharCount1(str));
    ????????System.out.println(
    " 中文字符數: " +
    ?Test.statGBCharCount2(str));
    ????}


    }


    可以看到,方法1中使用的辦法,可能局限性更大,不過也是一種思路。
    自己想的是第2種方法,用正則表達式直接過濾,也挺快捷。

    評論

    # re: 統計中英文字數的簡單方法  回復  更多評論   

    2006-11-07 08:58 by vteogdskf
    支持哦......

    i am ddm

    主站蜘蛛池模板: 亚洲国产精品成人一区| 国产成人A在线观看视频免费| 免费在线观看毛片| 在线观看亚洲专区| 国产免费久久精品| 老司机午夜性生免费福利| 丁香亚洲综合五月天婷婷| 麻豆91免费视频| 亚洲日韩欧洲无码av夜夜摸| 日韩电影免费在线观看网站| 亚洲国产香蕉碰碰人人| 精品熟女少妇a∨免费久久| 亚洲国产美女精品久久| 猫咪社区免费资源在线观看 | 十八禁无码免费网站| 久久久久亚洲精品美女| 国产精品久久免费| 美女视频黄免费亚洲| 免费国产成人午夜私人影视 | 亚洲国产综合精品中文字幕 | 久久久久亚洲av无码专区导航 | 国产一级大片免费看| 亚欧乱色国产精品免费视频| 亚洲精品无码久久千人斩| 最近免费中文字幕大全免费版视频| 亚洲小说区图片区| 国产免费拔擦拔擦8x| 视频免费在线观看| 亚洲国产综合人成综合网站00| 免费观看男人免费桶女人视频| 一级特级aaaa毛片免费观看| 婷婷亚洲久悠悠色悠在线播放| 免费无码又黄又爽又刺激| 曰批免费视频播放在线看片二| 亚洲AV无码久久精品蜜桃| 午夜男人一级毛片免费| 男女一边桶一边摸一边脱视频免费| 亚洲一区二区三区首页| 亚洲A∨午夜成人片精品网站 | 成年午夜视频免费观看视频| 有码人妻在线免费看片|