What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » how to use special characters in a switch

how to use special characters in a switch
Author: Message:
koen
New Member
*


Posts: 2
Joined: Feb 2008
O.P. how to use special characters in a switch
hi,
i have a question about using special characters in a switch. I have searched in the Scripting documentation,internet, this forum,... but i can't make it work.

I have a switch that works:
switch(Message) {
             case "questions": ChatWnd.SendMessage("sentence");
             break;
                ...

but now i want to compare 'Message' to a string with for example 'the'  in it.

like this: if Message = 'the best question ever'
how can i make the switch trigger this by the word 'question'?

switch(Message){
           case "^.question.$": ....                something like this doesn't work :s

i have read in the documentation that '.' matches any single character, '^' is the beginning of a string, '$' is the end of a string,...

but i can't make it work...
02-07-2008 09:35 AM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: how to use special characters in a switch
Well, you can make a regular expression which does this, but you can't use that in a switch...case block.

code:
var reQuestion = /(^|\s)question(\s|$)/si; //Create a regular expression which contains the word "question".
if(reQuestion.test(Message)) { //Test the message on the regular expression
   ChatWnd.SendMessage("Target valid!");
} else {
   ChatWnd.SendMessage("Aborting, couldn't see target.");
}
Note that I made this regular expression so it'll match the word "question" only. That means, it won't match "questions". If you want it to match any occurrence of "question", it gets much simpler. Then, you can simply use this instead of the original first line:
code:
var reQuestion = /question/i; //Create a regular expression which contains "question".

Note: In all these regular expressions, the "i" modifier was placed so they're case-insensitive. This is interesting if you capitalize the word for example. If you want it to be case-sensitive, just remove the "i" at the end. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-07-2008 10:52 AM
Profile E-Mail PM Web Find Quote Report
koen
New Member
*


Posts: 2
Joined: Feb 2008
O.P. RE: how to use special characters in a switch
oh thx! now it works :)
02-07-2008 11:01 AM
Profile E-Mail PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: how to use special characters in a switch
quote:
Originally posted by Mattike
code:
var reQuestion = /(^|\s)question(\s|$)/si;


I think you mean the following expression....

code:
var reQuestion = /\bquestion\b/i;

\b just denotes the end of a word (beginning or end), if you were to have the lines of a commar or questionmark after the word "question" then yours wouldn't fire.  Also the s modifier doesn't exist in JScript ;)
[Image: markee.png]
02-07-2008 01:13 PM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: how to use special characters in a switch
quote:
Originally posted by markee
Also the s modifier doesn't exist in JScript

I usedit fine and my script didn't work correctly without it ^o)
<Eljay> "Problems encountered: shit blew up" :zippy:
02-07-2008 10:00 PM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: how to use special characters in a switch
I couldn't find any documentation online about it being part of JScript.  However it is used for making the likes of "." match ANY character including \r and \n (both of these are not able to be matched by "." normally).

I wonder if we can also use the x modifier.... (I will test it out later)
[Image: markee.png]
02-08-2008 05:28 AM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: how to use special characters in a switch
Bah, okay then markee. I simply did some research on regular-expressions.info and I didn't scroll down enough. :P Thanks for correcting me.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-08-2008 08:22 AM
Profile E-Mail PM Web Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: how to use special characters in a switch
quote:
Originally posted by markee
I couldn't find any documentation online about it being part of JScript

http://www.javascriptkit.com/javatutors/redev2.shtml#
http://authors.aspalliance.com/wsk/aboutregularexpression.asp

Two pages from Google I found ^o)

This post was edited on 02-08-2008 at 05:49 PM by Spunky.
<Eljay> "Problems encountered: shit blew up" :zippy:
02-08-2008 05:42 PM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: how to use special characters in a switch
quote:
Originally posted by SpunkyLoveMuff
quote:
Originally posted by markee
I couldn't find any documentation online about it being part of JScript

http://www.javascriptkit.com/javatutors/redev2.shtml#
http://authors.aspalliance.com/wsk/aboutregularexpression.asp

Two pages from Google I found ^o)
I was talking specifically about the smodifier, your first link has g,iand m, and the second only talks about g and i.
[Image: markee.png]
02-09-2008 02:13 AM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: how to use special characters in a switch
Thats my fault then. I only saw the \s and thought it was that :$
<Eljay> "Problems encountered: shit blew up" :zippy:
02-09-2008 11:10 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On