String operation JS_

var STR = 'Hello World'
 // Get string length 
the console.log (str.length)
 // retrieve a specified character position 
the console.log (str.charAt ( '. 4' ))
 // retrieve a specified position character character encoding (the Unicode) 
the console.log (str.charCodeAt (. 4 ))
 // string successively spliced behind 
the console.log (str.concat ( 'WDC', 'YHF' ))
 // Get the string 2 labeled to start before the characters or character string of 4. (Argument can be negative) 
the console.log (str.slice (2,4 ))
the console.log (str.substring ( 2,4 ))
 // Get string subscript string 2 starts six characters rearwardly 
console.log (str.substr (2,6))

 result:

 

Guess you like

Origin www.cnblogs.com/wangdianchao/p/12609633.html