I am working on a web-application which returns JSON results as "/FileURL", I just need to get /FileURL as a result, means I need to remove quotation marks (double quotes) from returned JSON string using jQuery or Javascript, how can I do that?
You can try using regex to remove quotes from your string
var strWithOutQuotes= strWithQuotes.replace(/['"]+/g, '')
"
to only match double quotes.
Above solution will remove double quotes from your string.
If you just want to remove double quotes from start and end of you string you can try
var strWithOutQuotes= strWithQuotes.replace(/^"(.*)"$/, '$1');
Another way, possible the simplest example
var strWithOutQuotes= strWithQuotes.replace(/"/g, '');
here is the working fiddle of the last solution.
You can also simply use to remove all double quotes (")
str = str.replace(/"/g,"");
OR
If you want to remove only quotes around the string, you can use:
var str = '"Your "quoted" string"';
console.log( clean = str.replace(/^"|"$/g, '') );
//Your "quoted" string
OR
You can create custom JS function as shown below
function RemoveDoubleQuotes(a) {
var fIndex = a.indexOf('""');
var lIndex = a.lastIndexOf('""');
if(fIndex >= 0 && lIndex >= 0){
a = a.substring(fIndex+1, lIndex+1);
}
return a;
}
console.log(RemoveDoubleQuotes('"Testing"')); // Output-> Testing
console.log(RemoveDoubleQuotes('""test""')); // output -> test
If you want to remove the double quotes from JSON returned data, you can simply remove it using JSON.Parse method like below
JSON.parse(Double_quoted_string);
JSON.parse("My test"); // for example
You can also do it using eval
var No_Quotes_string= eval(Quoted_string);
If string has double quotes in start/end of the string, you can simple use .slice function which is easier to use than regex
str = str.slice(1, -1);
This is quick work, so work for limited strings only.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly