Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi String(ansi) to Url-Encoded String (https://www.delphipraxis.net/42783-string-ansi-url-encoded-string.html)

rossinie00 23. Mär 2005 20:08


String(ansi) to Url-Encoded String
 
gugux,
ich bin auf der suche nach einer procedure oder einer möglichkeit besser gesagt um einen ansistring in einen url-encoded string umzuwandeln. Nicht die buchstaben nur also die sonderzeichen.
zb. whitespace = + oder so
Danke

Lannes 23. Mär 2005 20:55

Re: String(ansi) to Url-Encoded String
 
Richtig: whitespace = +
Die anderen sind die Hexadezimalcodes z.B. das Zeichen "&" ist dann "%26"

Folgender Code ist die Umkehrung deiner Frage:
Delphi-Quellcode:
// Converts a URLencoded string to a normal string
Function DecodeURL(Instr: String): String;
Var
   S:       String;
   X:       Integer;
   C,N1,N2: Char;
Begin
   If Instr='' then exit;
   S := '';
   TempURL := Instr;                      // Copy URLencoded string
   Index := 1;                            // Reset string index
   Repeat
      C := GetURLchar;                    // Get next character
      If C='%' then                       // If it's a hex esc char
      Begin
         N1 := GetURLchar;                 // Get first digit
         N2 := GetURLchar;                 // Get second digit
         X := (Hex2Int(N1)*16)+Hex2Int(N2); // Convert to integer
         S := S+Chr(X);                    // Add character
      end else
      If C='+' then                        // If + then convert to space
         S := S+' ' else
      S := S+C;                            // Just add character
   Until C=' ';                            // Until no more in string
   Result := S;
end;
Hoffe das hilft Dir.

Lannes 23. Mär 2005 21:09

Re: String(ansi) to Url-Encoded String
 
Hallo,

das hast Du gesucht, oder :wink:
Delphi-Quellcode:
Function URLEncode(Value : String) : String;
Var I : Integer;
Begin
   Result := '';
   For I := 1 To Length(Value) Do
      Begin
         If Pos(UpperCase(Value[I]), ValidURLChars) > 0 Then
            Result := Result + Value[I]
         Else
            Begin
               If Value[I] = ' ' Then
                  Result := Result + '+'
               Else
                  Begin
                     Result := Result + '%';
                     Result := Result + IntToHex(Byte(Value[I]), 2);
                  End;
            End;
      End;
End;

rossinie00 23. Mär 2005 21:36

Re: String(ansi) to Url-Encoded String
 
das 2.
aber da klebt er bei: ValidURLChars als undef bezeichner.
muss ich da noch was in die uses eintragen?

Lannes 23. Mär 2005 21:46

Re: String(ansi) to Url-Encoded String
 
was vergessen :oops:
Delphi-Quellcode:
Const ValidURLChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$-_@.&+-!*"''(),;/#?:';

rossinie00 23. Mär 2005 22:10

Re: String(ansi) to Url-Encoded String
 
irgendwie macht es nicht das, wie's soll.

hab jetzt

test := URLEncode(test);
macht er nicht

Luckie 23. Mär 2005 22:14

Re: String(ansi) to Url-Encoded String
 
Warum die ganze Arbeit? MSDN-Library durchsuchenUrlCanonicalize ;)

Zitat:

Takes a URL string and converts it into canonical form.
[..]
This function performs such tasks as replacing unsafe characters with their escape sequences and collapsing sequences like "..\...".
Ist allerdings in der shlwapi.dll drinne und da weiß ich nicht, ob es dafür schon eine Übersetzung für Delphi gibt.

rossinie00 23. Mär 2005 22:18

Re: String(ansi) to Url-Encoded String
 
Zitat:

Ist allerdings in der shlwapi.dll drinne und da weiß ich nicht, ob es dafür schon eine Übersetzung für Delphi gibt.
desswegen die ganze arbeit *g*

Lannes 23. Mär 2005 22:40

Re: String(ansi) to Url-Encoded String
 
Zitat:

Zitat von rossinie00
irgendwie macht es nicht das, wie's soll.

hab jetzt

test := URLEncode(test);
macht er nicht

Poste mal deinen Code.
Bei mir klappt es, hab es gerade nochmal getestet.
Aus 'http://www.google.de/search?hl=de&q=Delphi&meta='
wird 'http://www.google.de/search?hl%3Dde&q%3DDelphi&meta%3D'

rossinie00 23. Mär 2005 22:43

Re: String(ansi) to Url-Encoded String
 
hab ich doch. ist relativ komplex und nicht gpl.
bei mir siehts so aus:

text := urlencode(memo1.text);
memo1.text := text ;


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:11 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz