2008/01/15 10:11

Two useful string functions - substr & substring


Now a days, javascript is widely used for web 2.0 programming.
In this case both function is very useful for string related algorithm.

You can simple get the required part of the string with high performance provided by client PC's performance.

1) substr() method extracts a specified number of characters in a string, from a start index.

Syntax: string.substr(start, length);

Quick Notes aout substr:

If start is negative, Internet Explorer returns the whole string. That’s wrong! IE should use the last character in the string.



2) Substring() method extracts the chars in a string between two specified indexes.

Syntax: string.Substring(start, stop);


Quick Notes about Substring:

If start equals stop, it returns an empty string.
If stop is omitted, it extracts characters to the end of the string.
If either argument is less than 0 or is NaN, it is treated as if it were 0.
If either argument is greater than string’s length, either argument will use string’s length.
If start > stop, then Substring will swap those 2 arguments.
Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 03:02 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 11:56 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:43 delete

    moneyideas