riverqh
22757
|
2006/4/8 20:48:34 |
dna32r 的写得不错,呵呵,Str、Val似乎是Delphi的RTL实现吧?也可能是我记错了。
楼主的有的也是不错,不过在简单的转换用Format似乎有些小题大做了,何况这些转换在应用很频繁的地方,是否应该考虑一下性能? |
dna32r
22623
|
2006/4/3 21:25:12 |
我以为我已经很菜了~没有想到还有比我还菜的~菜就菜呗..吹牛就是你的不对了~~~
完全用API完成:..uses Windows; function IntToStr(I: integer): string; begin Str(I, Result); end;
function StrToInt(S: string): integer; begin Val(S, Result, Result); end;
function HexToInt(Const HexValue: String) : Integer; begin Val('$'+HexValue, Result, Result); end;
function IntToHex(Const Value: Integer): string; const HexChars: array[0..15] of Char = '0123456789ABCDEF'; var iTemp: Integer; i: Integer; begin Result := ''; i := 0; while i<4 do begin case i of 0: iTemp := Value shr 24 and $FF; 1: iTemp := Value shr 16 and $FF; 2: iTemp := Value shr 8 and $FF; 3: iTemp := Value and $FF; end; Result := Result + HexChars[iTemp div 16]; Result := Result + HexChars[iTemp mod 16]; Inc(i); end; end;
function LowerCase(const S: string): String; begin Result:=CharLower(Pchar(S)); end;
function UpperCase(const S: string): String; begin Result:=CharUpper(Pchar(S)); end;
多学习少吹牛..这个是我平时没事的时候~自己写的.. |
luckygame
22325
|
2006/3/24 11:17:18 |
有很多错误,建议修改后再使用。 |
beyondbit
22317
|
2006/3/23 20:03:32 |
怎么把一个字符串一个一个的取出来转换成8位的二进制数据呢? |
iamdream
22311
|
2006/3/23 14:15:33 |
呀,刚才写错了: function ToHexStr(const S: string): string; const csHexChar: array[0..15] of Char = '0123456789ABCDEF'; var i: Integer; begin SetLength(Result, Length(S) shl 1); for i := Length(S) downto 1 do begin Result[i * 2] := csHexChar[Byte(S[i]) and $F]; Result[i * 2 -1] := csHexChar[(Byte(S[i]) and $F0) shr 4]; end; end; |
iamdream
22310
|
2006/3/23 14:05:29 |
最后一个,对大字符串,还是得用这个: function ToHexStr(const S: string): string; const csHexChar: array[0..15] of Char = '0123456789ABCDEF'; var i: Integer; begin SetLength(Result, Length(S) shl 1); for i := Length(S) downto 1 do begin Result[i * 2] := csHexChar[Byte(Result[i]) and $F]; Result[i * 2 -1] := csHexChar[(Byte(Result[i]) and $F0) shr 4]; end; end; |
wqy888
22294
|
2006/3/22 10:23:53 |
不错!早晚有用! |
iceker
22279
|
2006/3/21 13:30:56 |
顶\ 有没有汉字转换? |