Shoutbox

Getting partial String (argument to command.) - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Getting partial String (argument to command.) (/showthread.php?tid=69034)

Getting partial String (argument to command.) by AITEE on 12-01-2006 at 02:46 AM

Hi, What I need is to be able have something like /SOMETHINGCONSTANT and then here, something that is like a variable that changes each time.

so say for instance like say:

/Run iexplore.exe
(or something like that)
(so it would like be able to store that (the "iexplore.exe") and put it in a string var.
and then it would recognize the command and then also the argument.
Anyone understnad what I mean?


Thanks so much


AITEE

[EDIT]
I don't want to acutally run it I just want to have the command and then use the argument (in a variable)


RE: Getting partial String (argument to command.) by Spunky on 12-01-2006 at 02:54 AM

you could either use

code:
Message = Message.split(" ");
Debug.Trace(Message[0]); //The command
Debug.Trace(Message[1]); //The Parameter

Mulitple spaces can cause errors
or if you know the length of the command

code:
Command = Message.substr(0,5); //example
Parameter = Message.substr(6,Message.length); //Rest of Message


The best way however is to use a RegExp on the Message variable. I don't how these work but if you use the search function, CookieRevised usually advises to do this and has posted numerous examples

RE: Getting partial String (argument to command.) by phalanxii on 12-01-2006 at 05:56 AM

With regular expression:

code:
if(/^\/(.+?\b)(?: (.*))?$/.test(Message)) {
   var Command = RegExp.$1.toLowerCase();
   var Parameters = RegExp.$2;
   switch(Command) {
      case "run":
         myFunction(Parameters);
         break;
   }
}
I'm not sure if the regular expression is 100% correct, but it works as it's supposed to anyway. With this one, you can have spaces in your parameters and you don't need to count the length of the command. The parameter is also optional (if your command doesn't require parameters, it still works). If you need more than one parameter (separated by a space), you can use another regular expression.
RE: Getting partial String (argument to command.) by markee on 12-01-2006 at 06:14 AM

Have a look at the Script wiki here for information on creating commands that are recognised by MP!L, it's how I do it whenever I use a command.