I am fairly new to Switch.
I am trying to retrieve an url from a xml file and then replace the spaces with %20.
i use this javascript :
var newURI = theURI.replace(/s/g,"%20");
Original Path in XML :
http://194.178.160.247/pp/XGram/PDF/Visit Cor Spierenburg3_989_989_HR.pdf
After :
http://194.178.160.247/pp/XGram/PDF/Vis ... 989_HR.pdf
instead of the percentage char it puts in a path.
I have no idea what to try next, hopefully someone has some tips for me
Thanks!
Robert
replace spaces for %20 in javascript
-
- Newbie
- Posts: 2
- Joined: Thu Mar 31, 2011 9:39 am
replace spaces for %20 in javascript
Hi Robert,
What you're seeing is because %2 has special meaning when logging to the Switch message pane. But this should not be a problem, because the path is only substituted in the log, not in the actual variable. You can prove this with this code:
var theURI = "hello world";
var newURI = theURI.replace(/s/g,"%20");
File.write( "C:/out.txt", newURI );
s.log( 1, newURI );
In the Switch log you will indeed see an incorrect string, but if you check the file at C:/out.txt, you will see that it contains the correct "hello%20world".
Ben
What you're seeing is because %2 has special meaning when logging to the Switch message pane. But this should not be a problem, because the path is only substituted in the log, not in the actual variable. You can prove this with this code:
var theURI = "hello world";
var newURI = theURI.replace(/s/g,"%20");
File.write( "C:/out.txt", newURI );
s.log( 1, newURI );
In the Switch log you will indeed see an incorrect string, but if you check the file at C:/out.txt, you will see that it contains the correct "hello%20world".
Ben
-
- Newbie
- Posts: 2
- Joined: Thu Mar 31, 2011 9:39 am
replace spaces for %20 in javascript
Hi bens
thanks alot, it works
thanks alot, it works