|
-
May 21st, 2002, 05:16 PM
#1
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.
-
June 3rd, 2002, 12:52 AM
#2
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;
}
-
June 3rd, 2002, 10:48 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|