Shoutbox

# of characters in a message? - 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: # of characters in a message? (/showthread.php?tid=87279)

# of characters in a message? by citricsquid on 11-15-2008 at 04:53 PM

Hi,
I have a string called "Something" and I want to check what the first # of characters are, for example 3. I then want to strip the first # (for example, 2) characters from the string.

How would I go about doing this? I don't know much of the language used by MSGPLUS, I'm just using examples and my knowledge of PHP to work it out as I go along :)


RE: # of characters in a message? by Matti on 11-15-2008 at 05:25 PM

I suggest you have a look at a JavaScript String reference, such as the one at W3Schools. That should give you a good idea what methods you have.

  • To check the first X characters of a string:
    code:
    var strMessage = "/mycommand param1";
    if(strMessage.substr(0, 3) === "/my") {
       //First 3 characters equal "/my"
       //Do something useful here!
    }
    String.substr(X, Y) basically does the following: Give me the part of the string starting at position X containing at most Y characters. You could also use String.substring(X, Y), where Y is an ending position instead of a length. If you don't specify the second argument in substr() or substring(), it'll go on to the end of the string.
  • To strip the first X characters from a string:
    code:
    var strMessage = "one two three";
    var strPiece = strMessage.substr(4);
    //strPiece now contains "two three"
As you already have PHP knowledge, this should actually be piece of cake for you. Basically, String.substr(start, length) is the JScript equivalent for PHP's substr($string, $start, $length). The difference is that JScript does this in a more OOP-style. :)
RE: RE: # of characters in a message? by citricsquid on 11-15-2008 at 05:30 PM

quote:
Originally posted by Matti
OOP-style. :)

Cheers :D
I was sure I read somewhere what MSGPLUS used wasn't Javascript, maybe I'm going mad :D :$

Thanks, should be easy to do this now.
RE: # of characters in a message? by Volv on 11-15-2008 at 05:39 PM

It uses JScript which is not the same as Javascript but awfully similar :p


RE: RE: # of characters in a message? by citricsquid on 11-15-2008 at 05:43 PM

quote:
Originally posted by Volv
It uses JScript which is not the same as Javascript but awfully similar :p

:o)
Cheers, I'll try and remember that :D

RE: # of characters in a message? by Matti on 11-15-2008 at 08:27 PM

Mjeh, Plus! uses the JScript engine of the Windows Scripting Host which doesn't run in a browser and therefore doesn't have thewindow and document objects for interacting with the HTML document, but as for strings, numbers and other objects they're as good as identical for the beginning script developer. :)