What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Getting the Xth word of a sentence

Getting the Xth word of a sentence
Author: Message:
Riko15
New Member
*


Posts: 6
28 / Male / Flag
Joined: May 2010
O.P. Getting the Xth word of a sentence
Does anybody knows how to get the Xth word of a sentence?
In the mIRC scripting language it's $1

So an example: if John says 'Hi, I'm John', I want to have for example the second word 'I'm', what function should I use?
05-10-2010 03:06 PM
Profile PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Getting the Xth word of a sentence
js code:
var s = 'Hi, I\'m John';
var sArray = s.split(' ');
Debug.Trace(sArray[1]);

/*
    sArray:
        0 = Hi,
        1 = I'm
        2 = John
*/
05-10-2010 03:51 PM
Profile E-Mail PM Find Quote Report
Riko15
New Member
*


Posts: 6
28 / Male / Flag
Joined: May 2010
O.P. RE: RE: Getting the Xth word of a sentence
quote:
Originally posted by matty
js code:
var s = 'Hi, I\'m John';
var sArray = s.split(' ');
Debug.Trace(sArray[1]);

/*
    sArray:
        0 = Hi,
        1 = I'm
        2 = John
*/


Thnxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(Y)
Edit:

Doesn't work? o,o

This post was edited on 05-10-2010 at 04:33 PM by Riko15.
05-10-2010 04:28 PM
Profile PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Getting the Xth word of a sentence
Post your code because it does work.
05-10-2010 04:43 PM
Profile E-Mail PM Find Quote Report
Riko15
New Member
*


Posts: 6
28 / Male / Flag
Joined: May 2010
O.P. RE: RE: Getting the Xth word of a sentence
quote:
Originally posted by matty
Post your code because it does work.

[code]function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind){
    var s = Message;
    var sArray = s.split(' ');
    if(sArray[0] == "!tfd"){
        if(sArray[1] == "users"){
... some gay code of me xd ..
        }
    }
}
05-10-2010 05:31 PM
Profile PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Getting the Xth word of a sentence
Are these commands you are sending or commands that your contact is sending to you?

Other option is to do something like this:

js code:
function OnEvent_ChatWndReceiveMessage(oChatWnd, sOrigin, sMessage, nMsgKind){
    if (/^([\/|\!][^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {
        if (RegExp.$1 === '!tfd' && RegExp.$2 === 'users') {
                // put some code here
        }
    }
}

This post was edited on 05-10-2010 at 05:59 PM by matty.
05-10-2010 05:49 PM
Profile E-Mail PM Find Quote Report
Riko15
New Member
*


Posts: 6
28 / Male / Flag
Joined: May 2010
O.P. RE: RE: Getting the Xth word of a sentence
quote:
Originally posted by matty
Are these commands you are sending or commands that your contact is sending to you?

Other option is to do something like this:

js code:
function OnEvent_ChatWndReceiveMessage(oChatWnd, sOrigin, sMessage, nMsgKind){
    if (/^([\/|\!][^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {
        if (RegExp.$1 === '!tfd' && RegExp.$2 === 'users') {
                // put some code here
        }
    }
}


Both xD
05-10-2010 06:14 PM
Profile PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Getting the Xth word of a sentence
You are going to need to explain what you are trying accomplish. Both implementations of what you requested will work. But there may be some limitations of what you can actually do (based on the example you have given).
05-10-2010 08:02 PM
Profile E-Mail PM Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: Getting the Xth word of a sentence
Riko15: remember that you probably want to check sArray.length before trying to reference elements that may not be there.  I don't do Plus! scripting specifically, but that's just general coding common sense. 

05-11-2010 01:41 AM
Profile E-Mail 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