3

I want to remove the escape charecters from a string using jquery.

I know about the "escape()" in jquery but the issue is

For example I want to remove the escape charecters from the string "http://www.abc.com" if we

use escape() we get the result like this 'http%3A//www.abc.com' but i want the result like

'http//www.abc.com'. How it possible using jquery?

1
  • 1
    escape() is not jQuery, its part of javascript and is deprecated now. Commented Sep 20, 2012 at 8:26

3 Answers 3

9

There's nothing in jQuery about unescpaing.

Core javascript has escape() and unescape() function.

var url = 'http://www.abc.com';

var escaped_url = escape(url);

console.log(escaped_url); // logs 'http%3A//www.abc.com'

console.log(unescape(escpaed_url)) // logs 'http://www.abc.com'

i.e.

unescape(escape('http://www.abc.com')) === 'http://www.abc.com'

Sign up to request clarification or add additional context in comments.

3 Comments

this only an example my aim is create string with no special charecter
just unescape it. You will be able to create a string with no special character
unescape is deprecated now. What to use for same results? decodeURI* functions are for URI :) But I have to decode body of the response.
2

Use a regex? replace(/[^a-z0-9\s]/gi, '') function? Amend to characters you want to keep

2 Comments

':' is given only as example i want to remove all special charecters
actually this is for to create variables from file names that is file names may be like "absc(1)" or "absdf qw1" i want to strip the special charecters and get the name like this "absc1" or "absdfqw1"
-3

escape() encodes the special characters! To remove the characters, use for example replaceAll(String regex, String replacement).

In the regex-part you can insert all of the special character you want to remove.

1 Comment

Answer should include example.

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.