What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Getting partial String (argument to command.)

Getting partial String (argument to command.)
Author: Message:
AITEE
New Member
*


Posts: 3
Joined: Nov 2006
O.P. Getting partial String (argument to command.)
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)

This post was edited on 12-01-2006 at 02:50 AM by AITEE.
12-01-2006 02:46 AM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: Getting partial String (argument to command.)
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
<Eljay> "Problems encountered: shit blew up" :zippy:
12-01-2006 02:54 AM
Profile PM Find Quote Report
phalanxii
Full Member
***


Posts: 146
Reputation: 5
32 / Male / Flag
Joined: Aug 2006
Status: Away
RE: Getting partial String (argument to command.)
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.
12-01-2006 05:56 AM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1621
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Getting partial String (argument to command.)
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.
[Image: markee.png]
12-01-2006 06:14 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