GB码和BIG5码 |
缺席
|
KFC
一般會員 發表:43 回覆:73 積分:23 註冊:2003-03-27 發送簡訊給我 |
请问到底怎样区分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 發送簡訊給我 |
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 發送簡訊給我 |
引言:請教 banson1716 兄, 上面的 GBOffset WordToString GBOrder 是否要使用什麼函數庫才能達到, 或是可以 列出該 function 的內容呢..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
高階會員 發表:55 回覆:182 積分:167 註冊:2002-04-14 發送簡訊給我 |
我都用此簡綮轉換如有資訊不足我盡量補足
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 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |