全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:903
推到 Plurk!
推到 Facebook!

GB码和BIG5码

缺席
KFC
一般會員


發表:43
回覆:73
積分:23
註冊:2003-03-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-28 15:12:18 IP:210.77.xxx.xxx 未訂閱
请问到底怎样区分GB码和BIG5 我下载了这个段程序来区分它们,但发现有重码。请问BIG5和GB是会有重码的吗? function isBIG5(value: string): Boolean; begin Result := (Length(Value) >= 2) and ( (Value[1] >= #129) and (Value[1] <= #254) ) and ( ( (Value[2] >= #64) and (Value[2] <= #126) ) or ( (Value[2] >= #161) and (Value[2] <= #254) ) ); end; function isGB(value: string): Boolean; begin Result := (Length(Value) < 2) or ( ( (Value[1] > #161) and (Value[1] < #247) ) and ( (Value[2] >= #161) and (Value[2] <= #254) ) ); end;
banson1716
高階會員


發表:55
回覆:182
積分:167
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-03-31 04:18:37 IP:61.223.xxx.xxx 未訂閱
function isBIG5(value: string): Boolean;
begin
  if (length(value)>=2) then
  begin
   if (value[1] < #161) then
     Result := false
   else
     if ((value[2] >= #64) and (value[2] <= #126)) or ((value[2] >= #161) and (value[2] <= #254)) then
       Result := true
     else
       Result := false
  end
  else
    Result := false
end;    function isGB(value: string): Boolean;
begin
  if (length(value)>=2) then
  begin
    if (value[1] <= #161) and (value[1] >= #247) then
      Result := false
    else
      if (value[2] <= #161) and (value[2] >= #254) then
        Result := false
      else
        Result := true
  end
  else
    Result := true;
end;    function GBtoBIG5(value: string): string;
var
  leng, idx      : integer;
  tmpStr         : string[2];
  Offset         : integer;
  output         : string;
begin
  output := '';
  leng := length(value);
  idx := 1;
  while idx <= leng do
  begin
    tmpStr := value[idx]  value[idx   1];
    if isGB(tmpStr) then
    begin
      offset:=GBOffset(tmpStr);
      if (offset >= 0) and (offset <= 8177) then
      begin
        output := output   WordToString(GBOrder[offset]);
        inc(idx);
      end
      else
        output := output   value[idx] ;
    end
    else
      output := output   value[idx] ;        inc(idx, 1);
  end;
  Result := output;
end;
timhuang
尊榮會員


發表:78
回覆:1815
積分:1608
註冊:2002-07-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-03-31 09:36:47 IP:211.76.xxx.xxx 未訂閱
引言:
function GBtoBIG5(value: string): string;
var
  leng, idx      : integer;
  tmpStr         : string[2];
  Offset         : integer;
  output         : string;
begin
  output := '';
  leng := length(value);
  idx := 1;
  while idx <= leng do
  begin
    tmpStr := value[idx]  value[idx   1];
    if isGB(tmpStr) then
    begin
      offset:=GBOffset(tmpStr);
      if (offset >= 0) and (offset <= 8177) then
      begin
        output := output   WordToString(GBOrder[offset]);
        inc(idx);
      end
      else
        output := output   value[idx] ;
    end
    else
      output := output   value[idx] ;        inc(idx, 1);
  end;
  Result := output;
end;
請教 banson1716 兄, 上面的 GBOffset WordToString GBOrder 是否要使用什麼函數庫才能達到, 或是可以 列出該 function 的內容呢..
banson1716
高階會員


發表:55
回覆:182
積分:167
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-03-31 21:06:12 IP:61.223.xxx.xxx 未訂閱
我都用此簡綮轉換如有資訊不足我盡量補足 function GBOffset(value: string): integer; begin if length(value) >= 2 then Result := (Ord(value[1]) - 161) * 94 (Ord(value[2]) - 161) else Result := -1; end; function BIG5Offset(value: string): integer; begin Result := -1; if length(value) >= 2 then begin if (Ord(value[2]) >= 64) and (Ord(value[2]) <= 126) then Result := (Ord(value[1]) - 161) * 157 (Ord(value[2]) - 64); if (Ord(value[2]) >= 161) and (Ord(value[2]) <= 254) then Result := (Ord(value[1]) - 161) * 157 63 (Ord(value[2]) - 161); end end; function WordToString(value: Word): string; begin Result := Chr(Hi(value)) Chr(Lo(Value)); end;
KFC
一般會員


發表:43
回覆:73
積分:23
註冊:2003-03-27

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-03-31 21:15:00 IP:210.77.xxx.xxx 未訂閱
谢谢!但我的问题不是怎样进行BIG5和GB码间的转换。转换算法我有。我是由於GB码和BIG5实际是存在重码的,如果任意给出来源串,能否有某个判断法则来断定该串是繁是简?我试过将一个串进行isGB和isBIG5测试,发现如果串中若同时存在繁体和简体字,则转换失败(始终有部分字会乱码)
系統時間:2024-04-29 15:44:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!