Processing Strings
Introduction. Now that we have started with form validation you should be able to see the importance of being able to do other sorts of processing on inputs to improve validity. For example,
Obviously, this list can go on and on. There are also plenty of other situations that motivate string processing, but we will use these sorts of input validation situations to demonstrate code structures and method usefulness. The following table contains the properties associated with strings. |
Property | Description |
String.length |
This returns the number of characters in the string. |
The following table contains most of the methods associated with Strings. |
Method | Description |
String.anchor(name) |
This returns a copy of a string enclosed in an <A Name=> and </A> environment used for links. |
String.big( ) | This returns a copy of a string enclosed in <Big> and </Big> HTML tags. |
String.blink( ) | This returns a copy of a string enclosed in <Blink> and </Blink> HTML tags. |
String.bold( ) | This returns a copy of a string enclosed in <Bold> and </Bold> HTML tags. |
String.charAt(n) | This extracts the character at a given position in a string with numbering starting at 0. |
String.charCodeAt(n) | Returns the encoding of the character at a given position in the string. |
String.concat(value1, value2, ...) | Concatenates one or more values to a string. |
String.fontcolor(color) | This returns a copy of a string enclosed in <Font color=" "> and </Font> HTML tags. |
String.fontsize(size) | This returns a copy of a string enclosed in <Font size=" "> and </Font> HTML tags. |
String.indexOf(substring, start) | This returns the position of
the first occurrence of the substring within the String after the start
position. The start defaults to 0 if omitted.
-1 is returned if no such substring is found. |
String.italics( ) | This returns a copy of a string enclosed in <I> and </I> HTML tags. |
String.lastIndexOf(substring, start) | This returns the position of
the last occurrence of the substring within the String before the start
position. The start defaults to String.length - 1 if omitted.
-1 is returned if no such substring is found. |
String.link( ) | This returns a copy of a string enclosed in an <A HREF=> and </A> environment used for links. |
String.match(expression) | This has more elaborate options than I want to get into, but essentially, it searches the String for match(es) to the expression. |
String.replace(expression,replacement) | This searches the string for all occurrences of the expression and replaces them with the replacement. |
String.search(expression) | This searches the String for the expression and returns -1 if it isn't found. |
String.slice(start, end) | This returns a slice from the string specified by the start and end positions. If negative values are used to specify the start then the slice is implemented from the end of the string. If no end value is specified then all of the remaining characters after the start are returned. |
String.small( ) | This returns a copy of a string enclosed in <Small> and </Small> HTML tags. |
String.split(delimiter) | Splits the String into an array of substrings that were each segmented by using the specified delimiter. |
String.strike( ) | This returns a copy of a string enclosed in <Strike> and </Strike> HTML tags. |
String.sub( ) | Make a string a subscript using <Sub> and </Sub>. |
String.substr(start, length) | This returns a substring of a specified length starting with start. If negative values are used to specify the start then the substring is implemented working back from the end of the string. |
String.substring(from, to) | Returns a substring from the start position up to but not including the position determined by to. |
String.sup( ) | Make a string a superscript using <Sup> and </Sup>. |
String.toLowerCase( ) | Makes a copy of the string with all of the upper case characters converted to lower ase. |
String.toUpperCase( ) | Makes a copy of the string with all of the lower case characters converted to upper case. |
We will leave the examples to subsequent web pages. |