Pergunta

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?

Foi útil?

Solução

The following works for me:

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

Outras dicas

decodeURIComponent(str.replace(/%2b/g, '%20'));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top