还有一个,代码长一些。
function EnCode1(text:String): String;
var
i, j, len, cur :Integer;
s :String;
begin
Result := '';
len := Length(text);
i := 1;
j := 0;
while (i<=len) do
begin
if i < len then
cur := (ord(text[i]) shr j) or (ord(text[i+1]) shl (7-j)) and $FF
else
cur := (ord(text[i]) shr j) and $7F;
FmtStr(s, '%2.2X', [cur]);
Result := Result + s;
inc(i);
j := (j+1) mod 7;
if j = 0 then inc(i);
end;
end;{EnCode1}
function EnCode1(text:String): String;
var
i, j, len, cur :Integer;
s :String;
begin
Result := '';
len := Length(text);
i := 1;
j := 0;
while (i<=len) do
begin
if i < len then
cur := (ord(text[i]) shr j) or (ord(text[i+1]) shl (7-j)) and $FF
else
cur := (ord(text[i]) shr j) and $7F;
FmtStr(s, '%2.2X', [cur]);
Result := Result + s;
inc(i);
j := (j+1) mod 7;
if j = 0 then inc(i);
end;
end;{EnCode1}
解决方案 »
- 如何获得query组件更新记录数?
- 访问权限问题
- 如何使sqlserver客户端不装数据库驱动程序?
- 为什么DBcombobox中下拉时只显一个值?????(请高手快快指点一下啊!)
- 文件型数据库临时表问题!
- 没分了, 也问一个简单的小问题, 一个快节键?
- 关于unit单元文件的结构问题
- 求助高手
- 大侠帮忙?????
- 我编写的程序结束的时候用Application.destroy来关闭应用程序 可是在进程中还有 是不是我用错了
- 当MAPX中的MAP为miEditModeNode or miEditModeAddNode 时候,如何增加一个NODE了
- 格式化UNIT文件的工具,叫什么formater来的,用Ctrl+D激活?急!
var
i, len:Integer;
begin
Result := '';
i := 1;
len := Length(text);
while (i<=len) do
begin
Result := Result + Chr(StrToIntDef('$' + Copy(text, i, 4), 0));
inc(i, 4);
end;
end; {DisCode2}
是Unicode。我参照CP936写的,代码页和操作系统相关。
能看看EnCode1对应的DisCode1吗?
帮忙看看DisCode1。谢谢。
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := EnCode1(#$7F) + ',' + EnCode1(#$FF);
end;
var
i, j, len, a, b :Integer;
begin
Result := '';
len := Length(text);
i := 1;
j := 0;
while (i<=len) do
begin
if i > 2 then
a := StrToIntDef('$' + Copy(text, i - 2, 2), 0)
else a := 0;
b := StrToIntDef('$' + Copy(text, i, 2), 0);
Result := Result + Chr((a shr (8 - j)) or (b shl j) and $7F);
Inc(i, 2);
j := (j + 1) mod 7;
if j = 0 then Result := Result + Chr((b shr 1) and $7F);
end;
end;{DisCode1}
var
i, j, len, a, b :Integer;
begin
Result := '';
len := Length(text);
i := 1;
j := 0;
while (i<=len) do
begin
if i > 2 then
a := StrToIntDef('$' + Copy(text, i - 2, 2), 0)
else a := 0;
b := StrToIntDef('$' + Copy(text, i, 2), 0);
Result := Result + Chr((a shr (8 - j)) or (b shl j) and $7F);
Inc(i, 2);
j := (j + 1) mod 7;
if j = 0 then Result := Result + Chr((b shr 1) and $7F);
end;
end;{DisCode1}
var
i, j, len, a, b :Integer;
begin
Result := '';
len := Length(text);
i := 1;
j := 0;
while (i<=len) do
begin
if i > 2 then
a := StrToIntDef('$' + Copy(text, i - 2, 2), 0)
else a := 0;
b := StrToIntDef('$' + Copy(text, i, 2), 0);
Result := Result + Chr((a shr (8 - j)) or (b shl j) and $7F);
Inc(i, 2);
j := (j + 1) mod 7;
if j = 0 then Result := Result + Chr((b shr 1) and $7F);
end;
end;{DisCode1}