Javascript String Object Usage detailed

Source: Internet
Author: User
The code is as follows Copy Code

var a = "abcdefggdefg32asdf38";
document.write ("Original:" +a+ "<br/>")
document.write ("Bold:" +a.bold () + "<br/>");
document.write ("Large:" +a.big () + "<br/>");
document.write ("Italic:" +a.italics () + "<br/>");
document.write ("Delete line:" +a.strike () + "<br/>");
document.write ("Font size:" +a.fontsize + "<br/>");
document.write ("Font color:" +a.fontcolor ("#ff0000") + "<br/>");
document.write ("Superscript:" +a.sup () + "<br/>");
document.write ("Subscript:" +a.sub () + "<br/>");
document.write ("Uppercase:" +a.touppercase () + "<br/>");
document.write ("Uppercase:" +a.tolowercase () + "<br/>");
document.write ("Return index character:" +a.charat (3) + "<br/>");//This should be "D".
document.write ("Return Index:" +a.indexof ("F") + "<br/>");/this should be 5.
document.write ("Return index (reverse lookup):" +a.lastindexof ("F") + "<br/>");/this should be 9.
document.write ("Find string:" +a.search ("F") + "<br/>");//This should be 5, same as indexof.
document.write ("Replace string:" +a.replace ("a", "a") + "<br/>");//Replace A in string with a
document.write ("Return substring:" +a.slice (1,3) + "<br/>");//BC, return substring from index 1 to 3-1
document.write ("Split string:" +a.split ("D"). ToString () + "<br/>");//d as a separator, split string, return array
document.write ("Return substring:" +a.substr (1,2) + "<br/>");/return substring, starting with index 1, length 2, this is BC
document.write ("Return substring:" +a.substring (1,3) + "<br/>");//Same as Sclice (), return substring of index 1 to 3-1
document.write ("Match:" +a.match (/d+/) + "<br/>");//Regular match, return matching result, here is 32

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.