Use of string

Source: Internet
Author: User

Common Methods of string

Method

Description

Anchor ()

Create an HTML anchor

Concat ()

Connect strings

Indexof ()

Find the location where the character appears

Lastindexof ()

Find the last character

Charat ()

Returns the characters at the specified position.

Substring ()

Truncate string

Substr ()

Truncate string

Spilt ()

Split string

Tolowercase ()

Converts a string to lowercase letters.

Touppercase ()

Converts a string to uppercase or lowercase letters.

Sub ()

Returns the string as a subscript.

Sup ()

Display the string as a supermark

 

 

<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
/************ Create a String object ***********/
// Create a String object (method 1)
// Var STR = "Hello World ";
// Create a String object (method 1)
// Var STR = new string ("Hello World ");
 
/*********** Common methods for string objects ***************/
VaR STR = "Hello World ";
// Indexof is used to find the index location of the first occurrence of the substring. If no index is found,-1 is returned.
// Document. Write (Str. indexof ("O", 0); // output 4
// Document. Write (Str. indexof ("O", 5); // output 7
// Lastindexof is used to find the final position of the specified sub-string. If no result is found,-1 is returned. (Note: This method is used to search from the front of the string, the second parameter indicates the index location to start searching)
// Document. Write (Str. lastindexof ('O', str. Length ));
/********* Substring and substr *********************/

VaR STR = "Hello World ";
// Parameter 1: subscripts to be intercepted. Parameter 2: the number of characters to be truncated.
Document. Write (Str. substring (1, 3); // output el
Document. Write ("<br> ");
// Parameter 1: subscripts to be captured; parameter 2: number of characters to be truncated
Document. Write (Str. substr (1, 3 ));
Document. Write ("<br> ");
Document. Write (Str. Length); // The length of the output string

</SCRIPT>

</Head>

<Body>

</Body>

</Html>

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.