CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Searching for "+" using JScript

    Is it possible to search for a "+" using the search function in JScript? I am getting ther error message "Unexpected Quatifier" when I try to. So I have this little snippet that shows the problem. The search for an "o" works but the next search does not. I have also used "\+" and that does not work. There is probably a different way to escape the "+" but the documentation seems to not specify it.
    Code:
    var WshShell = WScript.CreateObject("WScript.Shell");
    var sValue = "one+two+three";
    WshShell.Popup(sValue.search("o"));
    WshShell.Popup(sValue.search("\x2B"));
    Something that is confusing is that replace works, as in:
    Code:
    sValue = sValue.replace("\x2B", " ");
    except replace only replaces the first occcurence; search is useful for determining if there are more.
    Last edited by Sam Hobbs; May 21st, 2002 at 05:37 PM.

  2. #2
    Join Date
    May 2002
    Location
    Israel
    Posts
    1
    May be use function charCodeAt() like in the following example:

    var WshShell = WScript.CreateObject("WScript.Shell");
    var sValue = "one+two+three";
    while (CharSearch(sValue,43) >= 0) {
    sValue = sValue.substr(CharSearch(sValue,43)+1);
    WshShell.Popup(sValue);
    }

    function CharSearch(string,charcode) {
    for (var i=0; i < string.length ; i++) {
    if (string.charCodeAt(i)==charcode)
    return i;
    }
    return -1;
    }

  3. #3
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Thank you.

    I already got an answer from the Microsoft JScript newsgroup. The answer is to use the following syntax:

    sValue.search(/\+/)

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

Featured