-
String Replace Method
I need to write a script that'll fnid a space, replace that space with a ` and then replace the ` with a ` and a space concatenated together. Now I tried finding a function in JavaScript that would allow me to do that but all I could find was some replace method that wants a regular expression as the first parameter. I found a good function in VBscript which allows Replace(string, replaceWhat, replaceWith) but I can't figure out how to call a VBScript from a JavaScript (I have never used VBScript before). Can anybody help out?
Thanks
:cool:
-
Guuuuurrttz.....
Uhm... no. Don't even bother with calling VBScript from JavaScript. And don't use VBScript in client side scripting. It is only supported by MS IE.
The second arguement of the VBScript Replace() function is the same as a Regular Expression.
Try something like this...
Code:
var myString;
myString.replace(/\s/g, " '");
I've never done this, and I have not tested this code.
As always, I recommend checking The Rhino.
-
got it, I tested it out and it worked how I needed it to, thanks.
I'm not sure what all the /'s and \'s do but I guess I'll have to reference a site on regular expressions one day. but for now this gets the job done. thanks.
:cool:
-
I've had a simulair problem, but I solved it bij unescape / escape.
The replace function didn't work well enoguh for me.
the \ is an escape char