How do I encode string for URI, for example Capitan's Hat -> Capitan%27s+Hat
or Сhristmas Hat -> %D0%A1hristmas+Hat
I tried, several methods encodeURIComponent(), encodeURI()
, but nothing brings close enough to what I need. Any idea how it is being encoded?
Escape() does bring relatively close result for capitan's hat, but then completely off for christmas hat.
EDIT:
As Thomas said, encodeURIComponent does the job, but how achieve replacing encoded characters, back to characters? As in example Сhristmas Hat -> "%D0%A1hristmas+Night"
I know replace(), targeting each character would work, but is there more universal option?