HTML Code:
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
String.prototype.splitAt=function(){return [this.substr(0,arguments[0]),this.substr(arguments[0])]}
</SCRIPT>
The above defines the prototype-function
splitAt.
The following is an example of the function in use:
HTML Code:
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
alert("abc".splitAt(2)[0])//alerts ab
alert("abc".splitAt(2)[1])//alerts c
</SCRIPT>
The way the function works:
The function always returns an Array with a length of 2 elements.
The given argument is the maxium string-length to allow for the the first element.
The second element is the remaining string that gets cut-off by the first element.