js string associated methods

1> concat () // return the new combined string

var A = "What what what it", B = "ssss" ; 
a.concat (B) 
// "Mody Mody Mody Mody ssss"

2 "indexOf () // Returns the index of the first matching, if not -1

var A = "What what what it", B = "ssss" 
a.indexOf (B)
 // - 1
 var C = "what" ; 
c.indexOf ( 'what' )
 // 1

3 "lastIndexOf () // Returns the index of the last matching without -1

var c = "What is the What is the East West" ; 
c.lastIndexOf ( 'what' )
 // 5

4> search () // Find the index string in substring, or -1 if no

var c = "What is the What is the East West" ; 
c.search ( 'what' )
 // 1

5> match () // retrieves the value specified in the string, the string returned, then return null no

var str="1 plus 2 equal 3"
str.match(/\d+/g)
// ["1", "2", "3"]

6 "replace (oldval, newval) // new replacement string matching string

var c = "What is the What is the East West" ; 
c.replace ( "what", 'the What' )
 // "What is the What is the East West"

7 "split () // for converting a character string into an array of strings

"| A | b | c" .split ( "|" )    
 // returns [ "", "A", "b", "c"] 

var d = "What is the What is the East West" ; 
d.split () 
// [ "What is the What is the East West"]

8> length // returns character length record

var d = "What is the What is the East West" ; 
d.length 
// 8

9> toLowerCase () // small letter toUpperCase () // turn uppercase letters

var str="ssss"
str.toUpperCase()
//"SSSS"
var mm="AAAA";
mm.toLowerCase()
//"aaaa"
var nn="11"
nn.toUpperCase()
//"11"

10> charAt (index) // method Returns the specified character position

var d = "What is the What is the East West" ; 
d.charAt ( 3 )
 // "East"

11> substring (a, b) // return the start position to the end position of the character      

    substr (a, length) // Returns the starting position of a string of length

    slice (a, b) // returns to the start position of the string b

Difference: When substr parameter is negative, a is followed by a string when a negative value for the real length, length of time to return an empty string or negative 0

   substring parameter a or b is replaced by a negative direct digital 0, the number is the numeric start position.

   slice () parameter is negative, then, with the string length, returns to the start to the end position of the character

Guess you like

Origin www.cnblogs.com/jiajiamiao/p/11731733.html