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. ?
Asked
Active
Viewed 2,059 times
3
1 Answers
3
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
- 105,752
- 40
- 168
- 205
-
Agreed. Just use `string.replace('%C2%A3','£');` – Josh May 18 '10 at 15:19
-
I swear that code sample wasn't there when I posted my comment... maybe I am going blind. – Josh May 18 '10 at 15:24
-
2Your 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 May 18 '10 at 15:26
-
@Josh: Michael might have put it in during the 5 minute silent editing window. – Andy E May 18 '10 at 15:29
-
@Andy Huh, never knew about that! – Josh May 18 '10 at 15:44
-
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. May 18 '10 at 16:17