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.