Results 1 to 4 of 4

Thread: String Replace Method

  1. #1

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236

    Angry 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

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    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.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236

    Cool

    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.


  4. #4
    Lively Member Base's Avatar
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    65
    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
    Ok

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width