Sign in to follow this  
Followers 0
iLoveAU3

Web browser - converting chars

11 posts in this topic

Hi guys,

i was looking if there is any thread on board were i can find the answer to my question and i have found none.

my question is:

is there any easy way how to replace all the "%20", "%27", etc. characters in given string?

eg. Agnieszka%20Chyli%C5%84ska%20-%20Kiedy%20powiem%20sobie%20do%C5%9B%C4%87[1].mp3

regards

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

use Asc()

... not a good idea.

You have there the hex ascii codes and you need the character - you have to use Chr(0x your code) - example Chr(0x20), Chr(0xC5) ...

To solve this - stringsplit using % and replace first 2 characters from 2nd return on ... with Chr(0x code) ...

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

... not a good idea.

You have there the hex ascii codes and you need the character - you have to use Chr(0x your code) - example Chr(0x20), Chr(0xC5) ...

To solve this - stringsplit using % and replace first 2 characters from 2nd return on ... with Chr(0x code) ...

Duh! Thanks, I wasn't really realizing it was hex so thanks for pointing out my mistake.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

$string="Agnieszka%20Chyli%C5%84ska%20-%20Kiedy%20powiem%20sobie%20do%C5%9B%C4%87[1].mp3"
_Convert($string)


Func _Convert($sString)
$sString=StringReplace($sString,"[1]","")
$aString=StringSplit($sString,"%")
ConsoleWrite(@CRLF&@CRLF &"! given string: " &$sString &@CRLF&@CRLF)
    
    For $i=2 To $aString[0]
        $sCode=StringLeft($aString[$i],2)
        $hCode="0x" & StringLeft($aString[$i],2)
        ConsoleWrite("converting:  '%" &$sCode &"' (" &$hCode &") -> " &@TAB&'"' &Chr($hCode) &'"' &@CRLF) 
        $sString=StringReplace($sString,"%" & $sCode, Chr($hCode))
    Next

ConsoleWrite(@CRLF &"! result: " &$sString &@CRLF&@CRLF)
EndFunc

nice try - thanks, but it does not work.

some of these "%C5%84", "%C5%9B", "%C4%87" codes are polish characters and they are beeing replaced with some unwanted chars.

this is what i get: "Agnieszka ChyliĹska - Kiedy powiem sobie doĹÄ.mp3"

instead of: "Agnieszka Chylińska - Kiedy powiem sobie dość.mp3"

(im not sure if you see difference)

is there any solution?

Edited by iLoveAU3

Share this post


Link to post
Share on other sites

already tried, doesn't work as well :P

Share this post


Link to post
Share on other sites

think there was no other way to make it done, however problem has been solved.

Func _ConvertCodesPL($sString)
ConsoleWrite(@CRLF&@CRLF &"Converting: " &@CRLF &$sString &@CRLF)
Local $aPLCode[20]=["%C4%84","%C4%86","%C4%98","%C5%81","%C5%83","%C3%93","%C5%9A","%C5%B9","%C5%BB","%C4%85","%C4%87","%C4%99","%C5%82","%C5%84","%C3%B3","%C5%9B","%C5%BA","%C5%BC"]
Local $aPLChar[20]=["Ą","Ć","Ę","Ł","Ń","Ó","Ś","Ź","Ż","ą","ć","ę","ł","ń","ó","ś","ź","ż"]
$sString=StringReplace($sString,"[1]","")

    ; replace all polish critical characters
    For $i=0 To 19
        If StringInStr($sString,$aPLCode[$i]) Then $sString=StringReplace($sString,$aPLCode[$i],$aPLChar[$i])
    Next

$aString=StringSplit($sString,"%")

    ; replace all other ascii characters
    For $i=2 To $aString[0]
        $sCode=StringLeft($aString[$i],2)
        $hCode="0x" & StringLeft($aString[$i],2)
        $sString=StringReplace($sString,"%" & $sCode, Chr($hCode))
    Next

If StringRight($sString,3)<>"mp3" Then $sString=$sString &".mp3"
ConsoleWrite($sString &@CRLF&@CRLF)
EndFunc

Share this post


Link to post
Share on other sites

think there was no other way to make it done, however problem has been solved.

Func _ConvertCodesPL($sString)
ConsoleWrite(@CRLF&@CRLF &"Converting: " &@CRLF &$sString &@CRLF)
Local $aPLCode[20]=["%C4%84","%C4%86","%C4%98","%C5%81","%C5%83","%C3%93","%C5%9A","%C5%B9","%C5%BB","%C4%85","%C4%87","%C4%99","%C5%82","%C5%84","%C3%B3","%C5%9B","%C5%BA","%C5%BC"]
Local $aPLChar[20]=["Ą","Ć","Ę","Ł","Ń","Ó","Ś","Ź","Ż","ą","ć","ę","ł","ń","ó","ś","ź","ż"]
$sString=StringReplace($sString,"[1]","")

    ; replace all polish critical characters
    For $i=0 To 19
        If StringInStr($sString,$aPLCode[$i]) Then $sString=StringReplace($sString,$aPLCode[$i],$aPLChar[$i])
    Next

$aString=StringSplit($sString,"%")

    ; replace all other ascii characters
    For $i=2 To $aString[0]
        $sCode=StringLeft($aString[$i],2)
        $hCode="0x" & StringLeft($aString[$i],2)
        $sString=StringReplace($sString,"%" & $sCode, Chr($hCode))
    Next

If StringRight($sString,3)<>"mp3" Then $sString=$sString &".mp3"
ConsoleWrite($sString &@CRLF&@CRLF)
EndFunc
Cool. I've been looking for a way to do this too. I was hoping there would be a 'simple' conversion to make html codes into unicode. It will be difficult to put all unrecognized codes into the array, but at least it will work! Well done!

Share this post


Link to post
Share on other sites

If you can work out how to get "%C4%84" and "%C4%86" to equal 260 and 262 then it should be straightforward to do something like:

ConsoleWrite(chrw(0260) & @CRLF)

To get the correct characters.

Share this post


Link to post
Share on other sites

;Credits to DaleHohm
$oSC = ObjCreate("ScriptControl")
$oSC.language = "Javascript"

$s1 = "; / ? : @ & = + $ , #"
$s2 = $oSC.eval("encodeURI('" & $s1 & "');")
$s3 = $oSC.eval("decodeURI('" & $s2 & "');")

ConsoleWrite( _
    "Original: " & $s1 & @CR & _
    "Encoded:  " & $s2 & @CR & _
    "Decoded:  " & $s3 & @CR )

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0