Wie transferiere ich Text in das " Percent encoding for URIs:"-Format?

  • Hallo,
    habe folgende Zeilen, welche mir den Text in Unicode umwandeln, wie komme ich von dort ins Percent encoding for URIs:"-Format?

    aus ß soll %C3%9F werden......laut google und http://rishida.net/scripts/uniview/conversion

    [autoit]

    $sText="ß"
    $struct=_WinAPI_MultiByteToWideChar ($sText,850) ;oder codepage 1252 ?
    $unicode_hex=(dllstructgetdata($struct,1))

    [/autoit]

    den Unicode hab ich jetzt, wie weiter?

    thx vorab
    Andy


    /edit/ habs gefunden....thx @ Prog@ndy

    Spoiler anzeigen
    [autoit]

    Func _URIEncode($sData)
    ; Prog@ndy
    Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"")
    Local $nChar
    $sData=""
    For $i = 1 To $aData[0]
    ConsoleWrite($aData[$i] & @CRLF)
    $nChar = Asc($aData[$i])
    Switch $nChar
    Case 45, 46, 48-57, 65 To 90, 95, 97 To 122, 126
    $sData &= $aData[$i]
    Case 32
    $sData &= "+"
    Case Else
    $sData &= "%" & Hex($nChar,2)
    EndSwitch
    Next
    Return $sData
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _URIDecode($sData)
    ; Prog@ndy
    Local $aData = StringSplit(StringReplace($sData,"+"," ",0,1),"%")
    $sData = ""
    For $i = 2 To $aData[0]
    $aData[1] &= Chr(Dec(StringLeft($aData[$i],2))) & StringTrimLeft($aData[$i],2)
    Next
    Return BinaryToString(StringToBinary($aData[1],1),4)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, '', _URIDecode(_URIEncode("testäöü fv")))

    [/autoit]

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    Einmal editiert, zuletzt von Andy (20. Oktober 2009 um 14:42)

  • http://www.autoitscript.com/forum/index.php?showtopic=46894

    Spoiler anzeigen
    [autoit]


    MsgBox(0,"", _UnicodeURLEncode("ß"))

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; _UnicodeURLEncode()
    ; Description: : Encodes an unicode string to be URL-friendly
    ; Parameter(s): : $UnicodeURL - The Unicode String to Encode
    ; Return Value(s): : The URL encoded string
    ; Author(s): : Dhilip89
    ; Note(s): : -
    ;
    ;===============================================================================

    [/autoit] [autoit][/autoit] [autoit]

    Func _UnicodeURLEncode($UnicodeURL)
    $UnicodeBinary = StringToBinary ($UnicodeURL, 4)
    $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
    $UnicodeBinaryLength = StringLen($UnicodeBinary2)
    Local $EncodedString
    For $i = 1 To $UnicodeBinaryLength Step 2
    $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
    If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then
    $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar)
    Else
    $EncodedString &= '%' & $UnicodeBinaryChar
    EndIf
    Next
    Return $EncodedString
    EndFunc ;==>_UnicodeURLEncode

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; _UnicodeURLDecode()
    ; Description: : Tranlates a URL-friendly string to a normal string
    ; Parameter(s): : $toDecode - The URL-friendly string to decode
    ; Return Value(s): : The URL decoded string
    ; Author(s): : nfwu, Dhilip89
    ; Note(s): : Modified from _URLDecode() that's only support non-unicode.
    ;
    ;===============================================================================
    Func _UnicodeURLDecode($toDecode)
    Local $strChar = "", $iOne, $iTwo
    Local $aryHex = StringSplit($toDecode, "")
    For $i = 1 To $aryHex[0]
    If $aryHex[$i] = "%" Then
    $i = $i + 1
    $iOne = $aryHex[$i]
    $i = $i + 1
    $iTwo = $aryHex[$i]
    $strChar = $strChar & Chr(Dec($iOne & $iTwo))
    Else
    $strChar = $strChar & $aryHex[$i]
    EndIf
    Next
    $Process = StringToBinary (StringReplace($strChar, "+", " "))
    $DecodedString = BinaryToString ($Process, 4)
    Return $DecodedString
    EndFunc ;==>_UnicodeURLDecode
    #endregion

    [/autoit]


    Edit: UPS, zu langsam mit suchen ;)

  • Zitat

    Edit: UPS, zu langsam mit suchen

    mach dir nix draus, hab vorher ne halbe Stunde lang die Tante gequält...nachdem ich hier http://en.wikipedia.org/wiki/Percent-encoding gelandet war, wars ja einfach ^^

    sollte man in die Hilfe aufnehmen....