Usage of Javascript string objects

Source: Internet
Author: User

This article will introduce the usage of string objects in detail. If you need to know about js string objects, you will not be able to refer to them.

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 ("strikethrough:" + a. strike () + "<br/> ");
Document. write ("font size:" + a. fontsize (10) + "<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/>"); // Here it should be "D"
Document. write ("Return Index:" + a. indexOf ("f") + "<br/>"); // Here it should be 5
Document. write ("Return Index (reverse search):" + a. lastIndexOf ("f") + "<br/>"); // Here it should be 9
Document. write ("search string:" + a. search ("f") + "<br/>"); // Here it should be 5, the same as indexOf
Document. write ("replacement string:" + a. replace ("a", "A") + "<br/>"); // replace a with
Document. write ("Return substring:" +. slice () + "<br/>"); // It should be bc and return the substring from Index 1 to 3-1.
Document. write ("split string:" +. split ("D "). toString () + "<br/>"); // uses D as the delimiter, splits the string, and returns an array.
Document. write ("Return substring:" +. substr () + "<br/>"); // return the substring, starting from Index 1. The length is 2. Here it is bc.
Document. write ("Return substring:" +. substring () + "<br/>"); // same as sclice (), returns the substring from 1 to 3-1.
Document. write ("match:" + a. match (/d +/) + "<br/>"); // regular match, returns the matching result, which 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.