function EncodeEnglish(var s:string):string;var i,j,len:Integer; cur:Integer; t:String; begin Result:='''';len:=Length(s); //j 用于移位计数 i:=1;j:=0; while i<=len do begin if i<len then//数据变换cur:=(ord(s[i]) shr j) or ((ord(s[i+1]) shl (7-j)) and $ff)elsecur:=(ord(s[i]) shr j) and $7f;FmtStr(t,''%2.2X'',[cur]);
Result:=Result+t;inc(i); //移位计数达到7位的特别处理 j:=(j+1) mod 7;if j=0 then inc(i);end;end;//end; function BinaryUniCode2Gb2312(ABinaryString:PChar;APosStart,APosEnd:integer):string;vari,iLen:integer;AscHexText,TmpHexStr:string;AsciiInt:integer ;AscLen,AscUniLen:integer;UniHexstr,GB2312:string;beginiLen:=Length(ABinaryString);for i:= APosStart-1 to APosEnd-1 dobeginAsciiInt:=ord(ABinaryString[i]);TmpHexStr:=Format(''%x'',[AsciiInt]);if length(TmpHexStr)=1 thenTmpHexStr:=''0''+TmpHexStr;AscHexText:=AscHexText+TmpHexStr;end; //forAscLen:=Length(AscHexText);AscUniLen:=AscLen div 4;for i:=0 to AscUniLen-1 dobeginUniHexstr:=Copy(AscHexText,i*4+1,4);// Gb2312 := Gb2312 + UnicodeToGb2312(HexAscii2DecimalInt(uniHexstr));end; // forresult := Gb2312 ;end;
function WideStringToUnicode_Ex(s:WideString;ADestStr:PChar;Limit:integer):integer;var sLen:integer;buffer:array[1..1024] of char;tmpchar:char;i:integer;beginsLen:=Length(s);if sLen>0 thenbeginCopyMemory(@buffer,Pointer(s),2*SLen);for i:=0 to SLen-1 dobegintmpchar:=buffer[2*i+1];buffer[2*i+1]:=buffer[2*i+2];buffer[2*i+2]:=tmpchar;end;if SLen>Limit thenSLen:=Limit;CopyMemory(ADestStr,@buffer,2*SLen);result:=SLen*2;result:=2*SLen;endelsebeginresult:=0;end;end;