質問

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?

役に立ちましたか?

解決

The following works for me:

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

他のヒント

decodeURIComponent(str.replace(/%2b/g, '%20'));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top