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