JavaScript-- string interception

<Script> 
        $ (Document) .ready ( function () { 

            // index starts from 0 

            the let STR = '123456789' ; 

            // use a parameter 
            the console.log (str.slice (. 3)) // from 4 start character, the last characters of the intercepted; Back "456789" 
            the console.log (str.substring (. 3)) // from the first four characters, the last characters of the intercepted; Back "456789" 

            // use two parameters 
            console .log (str.slice (. 1,. 5)) // starting from the second character, the first five characters; Back "2345" 
            the console.log (str.substring (. 1,. 5)) // the 2nd characters start to first five characters; return to "2345" 

            // If only one parameter and is 0, then return the entire parameter 
            console.log (str.slice (0 ))
            the console.log (str.substring ( 0 )) 

            // return the first character 
            the console.log (str.slice (0,. 1)) // . 1 
            the console.log (str.substring (0,. 1)) // . 1 

            // in the example above, we can see the use slice () and substring () is the same 
            // value returned is the same, but when the argument is negative, they are not the same as the return value, see below examples of 
            the console.log (str.slice (2, -5)) // 34 is 
            the console.log (str.substring (2, -5)) // 12 is 
            // from the above two examples can be seen that slice (2, - 5) actually Slice (2,4) 
            // minus 5 plus the length of the string into positive 4 9 (if the first number is equal to or greater than a second digit, the empty string); 
            // the substring ( 2, -5) is actually substring (2,0), a negative number is converted to 0, substring always smaller number as the start position. 


            //substr substring and the difference between 
            // the same point: If only a write parameter, both are the same effect: since all the current is taken from the string until the final subscript string string fragment. 
            = str2 the let '123456789' ; 
            the console.log (str2.substr ( 2)); //   "3456789" 
            the console.log (str2.substring (2)); //   "3456789" 

            // except that: the second parameter 
            // substr (startIndex, lenth): the second parameter is taken string length (the length of a character string taken from the starting point); 

            // the substring (startIndex, endIndex): the second parameter is the final string interception subscript (string taken between the two positions, 'containing free end of the head'). 

            the console.log ( "123456789" .substr (2,. 5)); //   "34567" from the index beginning 2, 5 intercept 
            the console.log ( "123456789" .substring (2,. 5)); //   "

            // summary: String.substr (startIndex, lenth) that we used from the designated position (startIndex) interception of a specified length (lenth) string; 
            // String.substring (startIndex, endIndex) This is the startIndex, endIndex in find a smaller value, and counting from the beginning of the string, the string between the interception position and a smaller value the larger value of the position, the length of the string is taken out to a larger value the smaller value among the poor. 


            // Function: Split () 
            // Function: using a separator to a specified string into the array stored in 

            the let Str3 = '1,2,3,4,5,6' ; 
            the let ARR = str3.split ( ' , ' ); 
            the console.log (ARR); // [ ". 1", "2", ". 3", ". 4", ". 5", ". 6"] 


            // function: John () 
            // function: you choose a delimiter arrays into a string of 

            the let myList = new new the array ( 'JPG', '
            let portableList = myList.join('|');
            console.log(portableList); //jpg|bmp|gif|ico|png


            
        })
    </script>

 

Guess you like

Origin www.cnblogs.com/dcy521/p/11460838.html