• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

            路漫漫,長修遠,我們不能沒有錢
            隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
            數據加載中……

            關于Utf8編碼的幾個函數

            最近一段時間老弄Utf8編碼,工作時寫了幾個函數,給大家指正一下

            //////////////////////////////////////////////
            //---------取得utf8字符的長度---------------//
            //Str:String 源字符串
            //Result:Integer utf8字符串長度
            class function TPduPush.getUTF8Len(Str: string): Integer;
            var
            i: integer;
            tmpChar: Pchar;
            begin
            tmpChar := pchar(str);
            i := 0;
            result := 0;
            while i < length(tmpChar) do begin
            if ord(tmpChar[i]) < $80 then begin
            i := i + 1;
            result := result + 1;
            end else begin
            i := i + 2;
            result := result + 3;
            end;
            end;
            end;

            ////////////////////////////////////////////////
            //----------取得字符串中的字符個數------------//
            //str:String 源字符串
            //Result:Integer 字符個數,兼容中文雙字節
            class function TPduPush.getAnsiLen(Str: string): integer;
            var
            i: integer;
            tmpChar: Pchar;
            begin
            tmpChar := pchar(str);
            i := 0;
            result := 0;
            while i < length(tmpChar) do begin
            if ord(tmpChar[i]) < $80 then
            i := i + 1
            else
            i := i + 2;
            result := result + 1;
            end;
            end;


            /////////////////////////////////////////////////
            //---------截取指定長度的utf8字符串------------//
            //str:string 源字符串
            //count:Integer 指定長度 一個漢字占三個字節,長度只能小,不能大
            //Result:string 截取后的utf8字符串
            class function TPduPush.getUTF8String(Str: string; count: Integer): string;
            var
            i, j: integer;
            tmpChar: Pchar;
            begin
            tmpChar := pchar(str);
            i := 0;
            j := 0;
            result := '';

            while i < length(tmpChar) do begin
            if j >= count then break; //英文轉碼后不能超過指定的位數
            if ord(tmpChar[i]) < $80 then begin
            result := result + string(tmpChar[i]);
            i := i + 1;
            j := j + 1;
            end else begin
            if j + 2 >= count then break; //漢字轉碼后不能超過指定的位數
            result := result + string(tmpChar[i]) + string(tmpChar[i + 1]);
            i := i + 2;
            j := j + 3;
            end;
            end;
            end;

            posted on 2006-01-19 15:06 Khan 閱讀(2182) 評論(1)  編輯 收藏 引用 所屬分類: Delphi

            評論

            # re: 關于Utf8編碼的幾個函數  回復  更多評論   

            請教一下QQ:36026877可以加QQ嗎?
            2012-06-06 20:34 | 肖偉立
            日日狠狠久久偷偷色综合96蜜桃| 99久久综合国产精品免费| 亚洲乱码中文字幕久久孕妇黑人| 77777亚洲午夜久久多喷| 精品免费tv久久久久久久| 久久久无码精品亚洲日韩软件| 波多野结衣AV无码久久一区| 2022年国产精品久久久久| 久久综合久久伊人| 精品久久久久久无码中文字幕一区 | 久久国产精品99国产精| 国产一区二区精品久久凹凸| 精品国产乱码久久久久软件| 91精品国产高清久久久久久91| 久久婷婷五月综合成人D啪 | 久久精品国产亚洲AV久| 国产成人久久777777| 伊人久久综合精品无码AV专区| 国产精品久久久99| 亚洲国产精品18久久久久久| 久久久网中文字幕| 99久久精品免费国产大片| 精品国产乱码久久久久久1区2区| 久久人妻AV中文字幕| 久久久综合香蕉尹人综合网| 日本道色综合久久影院| 久久综合噜噜激激的五月天| 久久毛片一区二区| 无码8090精品久久一区| 欧美日韩中文字幕久久久不卡| 久久国产精品久久精品国产| 久久影院综合精品| 亚洲av成人无码久久精品| 久久香综合精品久久伊人| 性欧美大战久久久久久久| 欧美性大战久久久久久| 久久精品国产一区二区三区不卡 | 中文精品久久久久人妻| 久久受www免费人成_看片中文| 日韩精品无码久久一区二区三| 久久本道久久综合伊人|