Click to See Complete Forum and Search --> : Searching for "+" using JScript


Sam Hobbs
May 21st, 2002, 05:16 PM
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.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:sValue = sValue.replace("\x2B", " ");except replace only replaces the first occcurence; search is useful for determining if there are more.

cam029
June 3rd, 2002, 12:52 AM
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;
}

Sam Hobbs
June 3rd, 2002, 10:48 AM
Thank you.

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

sValue.search(/\+/)