length

Checking If An Element Exists In jQuery

3rd February 2013

To verify that an element exists in the DOM you just need to use the .length property of a jQuery lookup. If the element is there then the number of elements found will be greater than 0.

Count Number Of Characters In A String With MySQL

30th September 2010

Today I needed to grab some data from a table where there was more than one occurrence of a string within another string. Basically, I needed to find all URL's from a table that were more than 3 levels deep (i.e. with 3 slashes), but realised there wasn't a function to do this in MySQL. I found an alternative method, but it got me thinking on how that might be possible.

MySQL Order Table By Character Length

24th September 2009

As part of debugging a bit of code I needed to know the longest possible field lengths that a record contains. You might need to know this if you are performing a database migration. The following query returns a field, along with the length of the string, and orders the results by the number of characters in that string.

</body></html>">

Pad A String In JavaScript

24th September 2008

Use the following function to pad a string with to a set length with a given string. The function takes three parameters. The string to be padded, the total number of characters that the string must be, and the string to be added. If the third parameter is not given then 0 is used as a default.

Some Useful String Functions In JavaScript

Here are a few of the built in JavaScript functions available.

To get the length of a string use the length variable. This returns the number of characters in a string.

  1. var str = 'abcdef';
  2. str.length; // returns 6

The charAt function will return the character at the point specified in the parameter. So to get the first character of a string use:

philipnorton42 Thu, 12/27/2007 - 18:40