0

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?

Mehmet Ince
  • 4,059
  • 12
  • 45
  • 65

2 Answers2

3

The following works for me:

decodeURIComponent("Mehmet%2bAli%2b%c3%96zcan").replace(/\++/g, ' ');
André Dion
  • 21,269
  • 7
  • 56
  • 60
1
decodeURIComponent(str.replace(/%2b/g, '%20'));
TachyonVortex
  • 8,242
  • 3
  • 48
  • 63