iLoveAU3 Posted October 13, 2008 Posted October 13, 2008 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
dbzfanatic Posted October 13, 2008 Posted October 13, 2008 Try removing the % and use Asc() would be my guess. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote]
enaiman Posted October 13, 2008 Posted October 13, 2008 (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 October 13, 2008 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 :)
dbzfanatic Posted October 13, 2008 Posted October 13, 2008 ... 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. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote]
iLoveAU3 Posted October 14, 2008 Author Posted October 14, 2008 (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 October 14, 2008 by iLoveAU3
dbzfanatic Posted October 14, 2008 Posted October 14, 2008 Try ChrW() instead. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote]
iLoveAU3 Posted October 14, 2008 Author Posted October 14, 2008 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
nikink Posted October 14, 2008 Posted October 14, 2008 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!
nikink Posted October 14, 2008 Posted October 14, 2008 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.
Pain Posted October 14, 2008 Posted October 14, 2008 ;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 )
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now