JavaScript base 13--js String Object

Source: Internet
Author: User

1 <!DOCTYPE HTML>2 <HTML>3     <Head>4         <MetaCharSet= "UTF-8">5         <title>The string object of JS</title>6         <Scripttype= "text/javascript">7             varStr= "ABCDEFG";8 document.write ("Str string:" +str);9             //the length of the stringTen document.write ("<br length of/> string:" +str.length); one             /*html-related Methods*/ a document.write (""); -             //bold () method, Bold - document.write ("Bold () method:" +Str.bold ()); the             //fontcolor () method, Sets the color of the string - document.write ("<br/>fontcolor () method:" +Str.fontcolor ("Red")); -             //fontsize () method to set the size of the font - document.write ("<br/>fontsize () method:" +Str.fontsize (5)); +             //link () method to display a string as a hyperlink - document.write ("<br/>link () method:" +Str.link ("hello.html")); +              a             //Sub () and Sup () methods to constrain the string to the Lower-right or upper-right corner at document.write ("<br/>sub () method:" +Str+str.sub ()); - document.write ("<br/>sup () method:" +Str+Str.sup ()); -             /*a similar approach to Java*/ - document.write (""); -             //concat () method, Connection string - document.write ("concat () method:" +Str.concat ("HIJKLMN")); in             //the CharAt () method returns the string at the specified position, starting at 0, and returning an empty string if the character position does not exist - document.write ("<br/>charat () method:" +Str.charat (2)); to             //the indexOf () method, which returns the position of the specified string, starts at 0, and returns 1 if the specified string does not exist . + document.write ("<br/>indexof () method:" +Str.indexof ("C")); -             varstr2= "a-b-c-d-e-f-g"; the document.write ("<br/>str2 string:" +str2); *             //split () method to split a string into an array $ document.write ("<br/>split () method:" +Str2.split ('-'));Panax Notoginseng             //Replace () method, replacement string - document.write ("<br/>replace () method:" +Str2.replace ('-', '_')); the             //substr () method that intercepts the string to intercept the n-bit characters from the specified position + document.write ("<br/>substr () method:" +Str.substr (2, 4)); a             //the substring () method, which intercepts the characters between two specified index numbers in a string, does not contain the character of the second index position (second index Position-1) the document.write ("<br/>substring () method:" +str.substring (2, 4)); +         </Script> -     </Head> $     <Body> $          -     </Body> - </HTML>

JavaScript base 13--js 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.