unit U_Cncode;{
 GB2312/BIG5 convert unit for Delphi 3,4,5,6,7
 ver 1.01
 By Tom Lee  1997/9/5
 E-Mail Address : [email protected]
 It is Freeware !
}interface
uses SysUtils;function GBtoBIG5(value: string): string; //虏锣羉
function BIG5toGB(value: string): string; //羉锣虏
function isGB(value: string): Boolean; //  IS 虏砰
function isBIG5(value: string): Boolean; //  IS 羉砰
 // 耞OSず絏
function getCharset: string;implementationvar
  BIG5Order: array[0..14757] of Word;
  GBOrder: array[0..8177] of Word;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;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;function BIG5toGB(value: string): string;
var
  leng, idx: integer;
  tmpStr: string[2];
  output: string;
  offset: integer;
begin
  output := '';
  leng := length(value);
  idx := 1;
  while idx <= leng do
  begin
    tmpStr := value[idx] + value[idx + 1];
    if isBIG5(tmpStr) then
    begin
      offset := BIG5Offset(tmpStr);
      if (offset >= 0) and (offset <= 14757) then
      begin
        output := output + WordToString(BIG5Order[offset]);
        inc(idx);
      end
      else
        output := output + value[idx];
    end
    else
      output := output + value[idx];    inc(idx);
  end;
  Result := output;
end;// 耞OSず絏function getCharset: string;
begin
  if (SysLocale.DefaultLCID = 2052) then
    Result := 'gb'
  else if (SysLocale.DefaultLCID = 1028) then
    Result := 'big5'
  else if (SysLocale.DefaultLCID = 1033) then
    Result := 'en';
end;initialization  BIG5Order[0] := $2020;
  BIG5Order[1] := $A3AC;
  BIG5Order[2] := $A1A2;
  BIG5Order[3] := $A1A3;
  BIG5Order[4] := $2020;
  BIG5Order[5] := $A1A4;
  BIG5Order[6] := $A3BB;
end.

解决方案 »

  1.   

    这里从0到8177,太多了,发不上来。initialization  BIG5Order[0] := $2020;
      BIG5Order[1] := $A3AC;
      BIG5Order[2] := $A1A2;
      BIG5Order[3] := $A1A3;
      BIG5Order[4] := $2020;
      BIG5Order[5] := $A1A4;
      BIG5Order[6] := $A3BB;
    end.
      

  2.   

    function GBtoBIG5(value: string): string; //国标到BIG5的转换
    function BIG5toGB(value: string): string; //BIG5转国标
    function isGB(value: string): Boolean; //  是否国标
    function isBIG5(value: string): Boolean; //  是否BIG5主要作用就是国标,BIG5码相互转换
      

  3.   

    bdmh,能说下起什么作用的吗? 为什么我老搞不懂这是干什么用的?
      

  4.   


    {
     GB2312/BIG5 convert unit for Delphi 3,4,5,6,7//GB2312和BIG5 相互转换
     ver 1.01
     By Tom Lee  1997/9/5
     E-Mail Address : [email protected]
     It is Freeware !
    }
    看注释 
      

  5.   


    大陆用GB,台湾用BIG5,记得很多台湾游戏都是BIG5码,看不懂吗
      

  6.   

    编码转换,如果不明白的话百度下GB2312和BIG5的区别
      

  7.   

    GB2312和BIG5 相互转换???我搞不懂GB2312和BIG5能做什么,一点涵义都没。
      

  8.   

    应该就是字符转化用的几个函数吧
    function GBtoBIG5(value: string): string; //从国标转化为BIG5编码
    function BIG5toGB(value: string): string; //从BIG5转化为国标
    function isGB(value: string): Boolean; //判断是否是国标编码格式
    function isBIG5(value: string): Boolean; //判断是否是BIG5编码格式用途感觉应该是为了使字符串能正常显示出来进行必要的转化,具体不是很清楚,知道的请多说点呀
      

  9.   


    你用不到,不等于这个功能就没用,你就把它当成翻译把,说一句BIG5的话,通过他翻译成普通话给你听
      

  10.   


    这样就能明白了 Thank you bdmh