Recently I decided to provide all the copyright dates on my sites in Roman numerals rather than decimal, just for something different. It’s not a major change I know, but it was something I wanted to do.
Go to page »
Just a quick and simple post, that’s possibly nothing new to you, but it might be useful to others.
If you want to perform a check on what a string starts with in Javascript, you can use the substring(startpos, endpos) method, startpos is a required parameter and indicates where in the string to start the extraction, endpos is optional and indicates where the extraction is to end (if not supplied, it will extract to the end of string).
For example, to check if a string starts with ‘ABC’ you would do the following:
var mystring = "ABCDEF";
var text = mystring.substring(0, 3);
if (text == 'ABC') alert("string starts with ABC!');
Note that if the string being extracted from is shorter than the amount to extract, e.g. using the above example if mystring = 'AB', the extraction will still work, but in this case text = 'AB'.