Question

My string is;

var str = "Mehmet%2bAli%2b%c3%96zcan";

And I want to get string;

var strDecoded = "Mehmet Ali Özcan";

I tried all of followings;

strDecoded = decodeURIComponent(str); // Fails;
strDecoded = decodeURIComponent((str + '').replace(/\+/g, '%20')); // Fails
strDecoded = _decodeURI(str); // Fails


function _decodeURI(str) {
  str = decodeURI(str);
  str = str.replace(/%27/g, "'");
  return str;
}

What can I do else to get correct string? any idea?

Était-ce utile?

La solution

The following works for me:

decodeURIComponent("Mehmet%2bAli%2b%c3%96zcan").replace(/\++/g, ' ');

Autres conseils

decodeURIComponent(str.replace(/%2b/g, '%20'));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top