Javascript-string Object

Source: Internet
Author: User

Javascript-string Object

<! DOCTYPE html>//common methods of strings        //1.charAt () returns the character at the specified positionConsole.log (' =========charat () ========= '); varABC = ' Telephone '; Console.log (Abc.charat (4));//P        //2.concat () connection string (array object also has this method for two arrays of connections)Console.log (' =========concat () ========= '); varA1 = ' My '; vara2 = ' name ';   Console.log (A1.concat (A2)); //myname        //3.indexOf (Searchvalue,fromindex) retrieves a string that returns the position of the first occurrence of a specified string value in a string        //Fromindex index value is: 0~ string length-1        //return if not found-1        varB1 = ' detection '; Console.log (' =========indexof () ========= '); Console.log (B1.indexof (' a '));//-1Console.log (B1.indexof (' e '));//1        //4.lastIndexOf () with indexof () backwards backward, returns the index of the character in the stringConsole.log (' =========lastindexof () ========= '); Console.log (B1.lastindexof (' E '));//3        //5.match (searchvalue|regexp) found a match for one or more regular expressions. The value returned isConsole.log (' =========match () ========= '); varSmatch = ' Hello World '; Console.log (Smatch.match (' L '));//["L", index:2, Input: "Hello World"]Console.log (Smatch.match (/l/));//["L", index:2, Input: "Hello World"]Console.log (Smatch.match (/l/g));//["L", "L", "L"] global match        //6.replace () replaces substrings that match regular expressionsConsole.log (' =========replace () ========= '); varSreplace = ' tony#163.com '; Console.log (Sreplace.replace (‘#‘, ‘@‘) ); Console.log (Sreplace.replace (/\d+/, ' 789 ') ); Console.log (Sreplace.replace (/(\w+) # (\w+)/, "$2#$1") ); //The 7.search () method is used to retrieve a substring specified in a string, or to retrieve a substring that matches a regular expression.         //returns the starting position of the first substring in the value stringobject that matches the regexp.         //if not found return-1Console.log (' =========search () ========= '); varSsearch = ' L, Index:2, Input:hello World '; Console.log (Ssearch.search (' 2 ') ); Console.log (Ssearch.search (K) ); //8.slice (start,end) extracts a fragment of a string and returns the extracted part in a new string.         //English [Sla?s] vt. Cut into slices;Console.log (' =========slice () ========= '); varSslice = ' [email protected] '; Console.log (Sslice.slice (5));//163.comConsole.log (Sslice.slice (4, 6));//@1        //the 9.split (Separator,howmany) method is used to split a string into a string array.         //English [Spl?t] Vt. split; separate < slang > (swift) leave; share        //Parameters: separator, length        //return value: Array        //The action performed by String.Split () is the opposite of what Array.join does. Console.log (' =========split () ========= '); varSsplit = ' jack+ jane+ jay+ Tony '; vars = ssplit.split (' + ')); Console.log (SinstanceofArray);//trueConsole.log (s); Console.log (Ssplit.split (' + ', 2) ); //The 10.substr (start,length) method extracts a specified number of characters from the start subscript in a string. Console.log (' =========substr () ========= '); varSsubstr = ' Hello world! '; Console.log (Ssubstr.substr (2));//Llo world!Console.log (Ssubstr.substr (2, 7));//Llo wor        //the 11.substring (start,stop) method is used to extract the character of a string intermediary between two specified subscripts.         //parameter is a non-negative integerConsole.log (' =========substring () ========= '); varssubstring = ' Hello world! '; Console.log (Ssubstring.substring (2));//Llo world!Console.log (Ssubstring.substring (2, 7));//Llo W</script>

Javascript-string Object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.