Академический Документы
Профессиональный Документы
Культура Документы
Objectives
How to modify strings with common string method
Creating dynamic effect with Substring method
JavaScript
JavaScript imposes no practical limit on the number of characters that a string can hold. Most older browser have a limit of 255 characters in length for a script statement.
You may need to divide these lines into smaller chunks
JavaScript
Joining Strings
Bringing two strings together as a single string is called concatenation The addition operator (+) links multiple strings together
JavaScript
JavaScript
To convert to Lowercase
var result = string.toLowerCase();
JavaScript
JavaScript
JavaScript
JavaScript
10
Another method, string.substring(), enables the extraction of a sequence of characters. NOTE: The character at the ending position is not included in the extracted string.
var stringA = banana daiquiri; var excerpt = stringA.substring(2, 6); //6-2 = 4 characters extracted //result: excerpt = nana; The number 2 desiganted the straring position of the extracted string (index begins at zero) The number 6 designates the number of charters to extract
JavaScript
11
12
JavaScript
13
String.substring() Method
The String.substring() method returns a substring of characters beginning at a specified index and ending at a specified index. We supply the beginning and ending indexes as arguments, separated with a comma. While the method includes the beginning index as part of the returned substring, it does NOT include the ending index.
JavaScript
14
15
Example Extract characters from a string: <script> var str="Hello world!"; document.write(str.substring(3)+"<br>"); document.write(str.substring(3,7)); </script> The output of the code above will be: lo world! lo w
JavaScript
16
JavaScript
17
pattern specifies the pattern of an expression modifiers specify if a search should be global, case-sensitive, etc.
JavaScript
18
JavaScript
19
JavaScript
20
JavaScript
21