Converting an URL to JSON encoded format
-
Hello there, I want to have a function that turns this : http://examplesite.com/folders/images/myphoto.jpg to this : http:\/\/examplesite.com\/folders\/images\/myphoto.jpg Can any of you help me with that? I'm not that good at JS but I need this : / Thanks.
-
Hello there, I want to have a function that turns this : http://examplesite.com/folders/images/myphoto.jpg to this : http:\/\/examplesite.com\/folders\/images\/myphoto.jpg Can any of you help me with that? I'm not that good at JS but I need this : / Thanks.
If all that you want is to replace a '/' with '\/' then I would recommend you look into the String.replace method you get with javascript.
function repl(url) {
return url.replace('/', '\/');
}But since you mentioned you were trying to turn a URL into JSON I am thinking there is more to what you are asking. In which case I would recommend the following: http://james.padolsey.com/javascript/parsing-urls-with-the-dom/[^]
-
If all that you want is to replace a '/' with '\/' then I would recommend you look into the String.replace method you get with javascript.
function repl(url) {
return url.replace('/', '\/');
}But since you mentioned you were trying to turn a URL into JSON I am thinking there is more to what you are asking. In which case I would recommend the following: http://james.padolsey.com/javascript/parsing-urls-with-the-dom/[^]
Thank you
-
Thank you
Lovely !! thanks !! CLT20 LIVE STREAMING 2014
Aloknath Jaiswal
-
Hello there, I want to have a function that turns this : http://examplesite.com/folders/images/myphoto.jpg to this : http:\/\/examplesite.com\/folders\/images\/myphoto.jpg Can any of you help me with that? I'm not that good at JS but I need this : / Thanks.
//the string to work with: var httpAddress = 'http://examplesite.com/folders/images/myphoto.jpg', //the char(s) to look for: charToRemp = '/', //the char(s) to change to: rempCharWith = '\\\\/'; //using RegExp function regexp\_changeCharsTo(charIn, from, to) { var regExpFrom = RegExp(from, 'g'); return charIn.replace(regExpFrom, to); } //using array map function arrMap\_changeCharsTo(charIn, from, to) { return charIn .split('') .map(function (chr) { if (chr === from) { return to; } return chr; }) .join(''); } //using for in loop function forIn\_changeCharsTo(charIn, from, to) { var fnString = ''; for (var cr in charIn) { if (charIn\[cr\] === from) { fnString += to; } else { fnString += charIn\[cr\]; } } return fnString; } //Test: var regexp\_test = regexp\_changeCharsTo(httpAddress, charToRemp, rempCharWith); var arrMap\_test = arrMap\_changeCharsTo(httpAddress, charToRemp, rempCharWith); var forIn\_test = forIn\_changeCharsTo(httpAddress, charToRemp, rempCharWith);