tags:

views:

20

answers:

1

Hi

is there any way i can make the encodeURIComponent method ignore certain characters for example if i don't want it to encode the £ sign. ?

thank you

+2  A: 

This is not possible without wrapping it yourself.

Probably the safest thing to do would be...not do this. If you're a thrill seeker, just undo the parts you want decoded after the encoding is complete.

Something like this might be a naive way (i.e. my way) of doing it:

encodeURIComponent(uri).replace('%A3','£')
Michael Haren
Agreed. Just use `string.replace('%C2%A3','£');`
Josh
I swear that code sample wasn't there when I posted my comment... maybe I am going blind.
Josh
Your method wouldn't perform a global replace, it would only replace the first occurrence of `£`. For a global replace `/%C2%A3/g` would be required for the first parameter.
Andy E
@Josh: Michael might have put it in during the 5 minute silent editing window.
Andy E
@Andy Huh, never knew about that!
Josh
certainly would work in a way but not the best code practice. the reason i was asking about this is that i'm trying to unescape a string in ruby that was encoded by the encodeURIComponent(uri), but it recognizes '%C2%A3' as a '?'.
Mo