Basic Package Type: boolean,number,string.
Here are the main ways to talk about string:
1. Character method
The character methods of String are CharAt () and charCodeAt (), both of which accept only one parameter (based on the 0 positional parameter), charAt () returns the character at that position, and charCodeAt () returns the character encoding;
Example:
var stringvalue = "Hello World";
Alert (Stringvalue.charat (1));// output Letter E
Alert (Stringvalue.charcodeat (1));// Output 101, which is the character encoding of the letter E
2. String manipulation methods
String manipulation methods are concat (), Slice (), substr (), substring (),
Contcat () can return a new string to be stitched together
Example: var stringvalue = "Hello";
Alert (Stringvalue.concat ("World", "!")); / Output Hello world!
Slice (), substr (), substring () can accept two parameters
(1) When 1 parameters are accepted:
Example: var stringvalue = "Hello World";
Alert (Stringvalue.slice (3));// Output lo world
Alert (STRINGVALUE.SUBSTR (3));// Output lo world
Alert (stringvalue.substring (3));// Output lo world
(2) When 2 parameters are accepted
Example: var stringvalue = "Hello World";
Alert (Stringvalue.slice (3,7));// output lo w o position is at 7, so do not return
Alert (STRINGVALUE.SUBSTR (3,7));// output lo worl
Alert (stringvalue.substring (3,7));// output lo w
(3) where the parameter is negative
var stringvalue = "Hello World";
Alert (Stringvalue.slice ( -3));// output rld .... Explanation =-3+11 (string length)
Alert (STRINGVALUE.SUBSTR ( -3));// output Rld
Alert (stringvalue.substring ( -3));//Output Hello world ..... Convert all negative numbers to 0
Alert (Stringvalue.slice (3,-4));// output lo w
Alert (STRINGVALUE.SUBSTR (3,-4));// Output "", the method will be negative first plus string length, minus the second one converted to 0
Alert (stringvalue.substring (3,-4));// output Hel, this method converts all negative numbers to 0
4. Trim () method
Creates a string-by-body that returns characters before and after the deletion of a string, some browsers support Trimleft (), TrimRight ()
Example: var stringvalue = "Hello World";
Alert (Stringvalue.trim ());// Output Hello world
5. String Case Conversion
toLowerCase ()
toUpperCase ()
Tolocallowercase ()//For specific regions
Tolocaluppercase ()//For specific regions
6. String pattern Matching
Match () accepts only one parameter
7. Localcompare () method
JavaScript learning process (1)