A string object in JavaScript details

Source: Internet
Author: User

  This article mainly describes the string object in JavaScript, and the friend you need can refer to the following

The sting string object is one of the built-in objects provided by JavaScript.     Notice here that the first character in the string is the No. 0 digit and the second is the 1th digit.     1. method to create a string object     [var] String object Instance name = new String (string)     or Var string object instance Name = String Value & nbsp   Example:    var str = "Hello World";    var str1 = new String ("Here is a String");    2.St Ring Properties     Length: Returns the length of the string     var intlength = str.length//intlength = 11    3.String method &nb Sp   CharAt (*): Returns a single character     var x = "ABCDEFG" at the first bit of the string; var y = X.charat (3); Y= "D"     charcodeat (*): Returns the ASCII code of a single character with a string located at the * bit     does not repeat the following   codes: fromCharCode (): Accepts a specified Unicode value, and then returns a string.     document.write (String.fromCharCode (72,69,76,76,79)); The output is hello    indexOf (): Find another string object from the string, find the successful return position, or return to -1    document.write ("Children". IndexOf ("L", 0)); The output result is 3    document.write ("Children". IndexOf ("L", 1)); The output result is 3    document.write ("Children". IndexOf ("L", 4)); Output resultsis -1    LastIndexOf (): Similar to the indexof () method, the difference is to look in the opposite direction, looking backwards     document.write ("Children"). LastIndexOf ("L", 4)); The output is 3    Split (separator character): Returns an array that is separated from the string, separating the characters that determine where the separation is.     ' L&o&v&e '. Split (' & '); Return array l,o,v,e    SUBSTRING (): the equivalent of the clipping function of the string     substring (< beginning >[,<))     document.write ("Children". Substring (1,3)); Output is hil    substr (): Also equivalent to cropping, note the different     substr (< start >[,< length) of the substring ())   code as follows: document.write ("Children". substr (1,3)); The output result is Hil. Here to notice compared with substing, although the results are the same, but the algorithm and ideas are different.     toLowerCase () and toUpperCase (): function is similar, just return a string with the same original string, the only difference is that all the letters are lowercase, the latter is uppercase.     document.write ("Love". toLowerCase ()); The output result is love    document.write ("Love". toUpperCase ()); Output is love   

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.