1

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?

2
  • See stackoverflow.com/questions/3803716/…. Commented Aug 2, 2013 at 12:42
  • This is the wrong problem, your problem is how those strings are generated, a space should be %20, not a + or even %2b Commented Aug 2, 2013 at 12:56

2 Answers 2

4

The following works for me:

decodeURIComponent("Mehmet%2bAli%2b%c3%96zcan").replace(/\++/g, ' ');
Sign up to request clarification or add additional context in comments.

Comments

1
decodeURIComponent(str.replace(/%2b/g, '%20'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.