The sting string object is one of the built-in objects provided by JavaScript.
Note here that the first character in the string is the No. 0 digit and the second is the 1th digit.
1. How to create a string object
[Var] String Object Instance name = new String (string)
or var string object instance Name = String value
Example:
var str = "Hello world";
var str1 = new String ("This is a string");
Properties of 2.String
Length: Returns the lengths of the string
var intlength = Str.length//intlength = 11
Method of 3.String
CharAt (*): Returns a single character with a string at the first * bit
var x = "ABCDEFG"; var y = X.charat (3); y= "D"
charCodeAt (*): Returns the ASCII code of a single character with a string at the first * bit
Without repeating
Copy Code code as follows:
fromCharCode (): Accepts a specified Unicode value and returns a string.
document.write (String.fromCharCode (72,69,76,76,79)); The output is Hello
IndexOf (): Finds another string object from the string, finds the successful return position, or returns-1
document.write ("Children". IndexOf ("L", 0)); The output is 3.
document.write ("Children". IndexOf ("L", 1)); The output is 3.
document.write ("Children". IndexOf ("L", 4)); The output is 1.
LastIndexOf (): And the IndexOf () method is similar, the difference is to find the opposite direction, looking forward from the back
document.write ("Children". LastIndexOf ("L", 4)); The output is 3.
Split (separator character): Returns an array that is separated from the string, separating the characters that determine where the separation is.
' L&o&v&e '. Split (' & '); Returns an array l,o,v,e
SUBSTRING (): the equivalent of the cutting function of the string
SUBSTRING (< beginning >[,< final;])
document.write ("Children". Substring (1,3)); The output result is Hil
SUBSTR (): Also equivalent to cropping, note the difference with substring ()
SUBSTR (< beginning >[,< length)
Copy Code code as follows:
document.write ("Children". substr (1,3)); The output result is Hil. Here to notice compared with substing, although the results are the same, but the algorithm and ideas are different.
toLowerCase () and toUpperCase (): function similar, just return a string with the same original string, the only difference is that the former all letters are lowercase, the latter is uppercase.
document.write ("Love". toLowerCase ()); The output is love.
document.write ("Love". toUpperCase ()); The output is love.