Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I need to convert strings to be URI conform. That means replacing spaces by %20 and so on. Before I go back writing nested Replace statements, I wondered if there is something like an encodeURI() function? I haven't found anything similiar, but any hint or help is highly appreciated.
Thank you!
Florian
After looking around a while I believe there is no such function
After looking around a while I believe there is no such function
So I began to write some little "parser". Feel free to add your comments and ideas:
CharMap:
LOAD * INLINE [
Char, ASCII
" ", %20
(, %28
), %29
., %2E
-, %2D
ß, ss
ä, ae
ö, oe
ü, ue
Ä, Ae
Ö, Oe
Ü, Ue
];
Sub URIencoder(txt)
LET recNo = 1;
DO WHILE recNo < FieldValueCount('Char') + 1;
LET from = FieldValue('Char', $(recNo));
LET to = FieldValue('ASCII', $(recNo));
LET txt = Replace('$(txt)', '$(from)', '$(to)');
LET recNo = recNo + 1;
LOOP
End Sub
DROP TABLE CharMap;
Hi Florian,
I think the right way is using Jscript encodeURI function because there are endless of UTF chars especially if you have to deal with web sources ans URL parameters (like Twitter):
This is an example for a Jscript macro code in QV:
function encode (uri){
return encodeURI(uri);
};
- Ralf
Btw. there is a new solution I found to load a full encoding list and use it with MapSubString():