Autor Beitrag
g1o2k4
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 493



BeitragVerfasst: Mo 28.08.06 16:35 
hallo

wie wandele ich einen string in dem ein wort steht in den hex wert um ?

grüße g1o
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Mo 28.08.06 16:37 
Einen String oder einen Integer jetzt?

//Für Integer: IntToHex(200, 2);

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
g1o2k4 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 493



BeitragVerfasst: Mo 28.08.06 16:40 
ich hab ne variable s:string; und den hexwert möchste ich ausgeben, in nem label oder memo oder so
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 28.08.06 16:45 
Du musst jedes Zeichen des Strings durchgehen (Schleife) und den Zeichenwert von jedem Zeichen (-> Funktion Ord) bestimmen. Diesen kannst du dann mit IntToHex in den entsprechenden Hex-Wert umwandeln.
g1o2k4 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 493



BeitragVerfasst: Mo 28.08.06 17:06 
in der bibliothek JclStrings.pas ist eine funktion: function StrToHex(const Source: string): string;

ich hab das dann eingebundend und

ausblenden Delphi-Quelltext
1:
Memo1.text := StrToHex(s);					

geschrieben, was mir eigentlich einen string ausgeben sollte, aber Memo1. bleibt leer.


die ganze funktion sieht so aus:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
function StrToHex(const Source: string): string;
var
  Index: Integer;
  C, L, N: Integer;
  BL, BH: Byte;
  S: string;
  {$IFDEF CLR}
  sb: StringBuilder;
  {$ENDIF CLR}
begin
  {$IFDEF CLR}
  sb := StringBuilder.Create;
  {$ELSE}
  Result := '';
  {$ENDIF CLR}
  if Source <> '' then
  begin
    S := Source;
    L := Length(S);
    if Odd(L) then
    begin
      S := '0' + S;
      Inc(L);
    end;
    Index := 1;
    {$IFDEF CLR}
    sb.Length := L div 2;
    {$ELSE}
    SetLength(Result, L div 2);
    {$ENDIF CLR}
    C := 1;
    N := 1;
    while C <= L do
    begin
      BH := CharHex(S[Index]);
      Inc(Index);
      BL := CharHex(S[Index]);
      Inc(Index);
      Inc(C, 2);
      if (BH = $FFor (BL = $FFthen
      begin
        Result := '';
        Exit;
      end;
      {$IFDEF CLR}
      sb[N] :=
      {$ELSE}
      Result[N] :=
      {$ENDIF CLR}
        Char((BH shl 4) + BL);
      Inc(N);
    end;
  end;
  {$IFDEF CLR}
  Result := sb.ToString();
  {$ENDIF CLR}
end;
Zeerox
Hält's aus hier
Beiträge: 9

Win XP, SuSe 10
Delphi 7 Enterprise, C++ Builder
BeitragVerfasst: Mo 28.08.06 17:08 
Mit den JEDI-Komponenten kann man auch den StrToHex Befehl verwenden.;)

Edit:Ok warst schneller ^^
g1o2k4 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 493



BeitragVerfasst: Mo 28.08.06 17:13 
erklär mir mal bitte wie... ! ^^
galagher
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2556
Erhaltene Danke: 45

Windows 10 Home
Delphi 10.1 Starter, Lazarus 2.0.6
BeitragVerfasst: Di 29.08.06 14:30 
user profile icong1o2k4 hat folgendes geschrieben:
ich hab ne variable s:string; und den hexwert möchste ich ausgeben, in nem label oder memo oder so

StringToHex:
www.delphi-forum.de/...ghlight=inttohex+ord

_________________
gedunstig war's - und fahle wornen zerschellten karsig im gestrock. oh graus, es gloomt der jabberwock - und die graisligen gulpen nurmen!