[DELPHI] - Convert String To Hex?-VBForums
Results 1 to 4 of 4

Thread: [DELPHI] - Convert String To Hex?

Hybrid View

  1. #1

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    [DELPHI] - Convert String To Hex?

    Code:
    function StringtoHex(Data: string): string;
    var 
      i, i2: Integer;
      s: string;
    begin
      i2 := 1;
      for i := 1 to Length(Data) do
      begin
        Inc(i2);
        if i2 = 2 then
        begin
          s  := s + ' ';
          i2 := 1;
        end;
        s := s + IntToHex(Ord(Data[i]), 2);
      end;
      Result := s;
    end;

  2. #2
    New Member
    Join Date
    Apr 2009
    Posts
    1

    Re: [DELPHI] - Convert String To Hex?

    Perhaps this is shorter:

    Code:
    {Convert a string to a hex string, obviously twice as long. Rudementary encryption, good for passing funny characters as parameters in a url}
    function StringToHex(S: String): String;
    var I: Integer;
    begin
      Result:= '';
      for I := 1 to length (S) do
        Result:= Result+IntToHex(ord(S[i]),2);
    end;
    The reverse:

    Code:
    {Reverse of StringToHex(), assuming even size of 2 hex digits per represented character}
    function HexToString(H: String): String;
    var I: Integer;
    begin
      Result:= '';
      for I := 1 to length (H) div 2 do
        Result:= Result+Char(StrToInt('$'+Copy(H,(I-1)*2+1,2)));
    end;
    Might be of some use to someone.

  3. #3
    New Member
    Join Date
    Dec 2009
    Posts
    1

    Re: [DELPHI] - Convert String To Hex?

    Hi guys, to double check my programs, I use this hex to string tool
    pretty cool!
    David

  4. #4
    New Member
    Join Date
    Jan 2012
    Location
    Cedar Rapids, IA
    Posts
    1

    Thumbs up Re: [DELPHI] - Convert String To Hex?

    Thanks Taqyon for the sample code. Simple and elegant.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.