Methods characters


 
 var str="nothing  impossible"

  

// indexOf returns the position of a string
  var A = str.indexOf ( " H " ) 
  the console.log (A)    // . 3 
  the console.log (str.indexOf ( " I " , . 6 )) // from a [6] inquiry start position I; // 8

 


// query can not return -1

// charAt returned by the specified index (subscript) character
 console.log(str.charAt(2))  //t

 



// substr interception
the console.log (str.slice (l, 3))   // taken a [1] to a [3] of the former a [2] 
 the console.log (str.substr (1,9)) // taken a [1] to a [9], comprising a1 and A9 
 the console.log (str.substring (l, 3)) // same slice

 



// split Split string by specifying the character, returns an array
console.log(str.split(" ")) //["nothing", "impossible"]

 


// replace replace characters
  console.log(str.replace("n","w")) //whing impossible

==================================================================================================================================================================================

1.indexOf (Data, Start);    // for returning an array or a predetermined position of the character string or character string; 
        var STR = " ABCDEFG"; 
        str.indexOf ( "A" ); // return the current 0 queries where the subscript character position, if not, return -1, start represents a start from the first of several inquiries. 

    2.charAt (index); // Returns the specified character position, index representing a subscript 

    3.substr (n, m);            

    4.substring (n, m); // return from the specified position n, to the end position (not string containing m), if the end position is not specified, from the start position to the end 

    5.slice (n, m); // similar with the substring, the array should be noted that the method and slice () is 

    6.split ( "- " ); // divided by the specified character string, returns a list 

    7.replace ( " needs to be replaced character string "," string "after replacement ) // will replace some of the character string number of additional characters. Best with regular use 

http://www.w3school.com.cn/jsref/jsref_obj_string.asp

 

Guess you like

Origin www.cnblogs.com/hy96/p/11389544.html