PDA

Click to See Complete Forum and Search --> : String Replace Method


TheGoldenShogun
Oct 22nd, 2001, 02:41 PM
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:

CiberTHuG
Oct 22nd, 2001, 03:09 PM
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...


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 (http://www.oreilly.com/catalog/jscript3/).

TheGoldenShogun
Oct 22nd, 2001, 03:17 PM
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:

Base
Oct 23rd, 2001, 01:33 AM
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