iandevlin.com

Icon

A mixture of musings on web design & development, history, and life

Site and blog theme update

I’ve made a few tweaks and configurations to this blog site, as you can no doubt see. The main change is the expanded navigation, with the inclusion of a contact form and a resources for web developers page, which will be added to when I find something worthwhile.

I’ve also made a colour change to iandevlin.com, changing the background colour from grey to white in order to fit with the look of this blog.

Feel free to let me know what you think!

Javascript: checking what a string starts with

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'.