Substring function details

Source: Internet
Author: User
From: http://www.cnitblog.com/yemoo/archive/2006/06/17/12421.html

Note:
1. Both s must be in lower case!
2. Method of the string object.
3. Index subscript starts from 0
4. Returns a string from start to end, but does not contain characters at the end index position.

Substring Method

Return locationStringThe substring at the specified position in the object.

Strvariable.Substring (Start,End)
"String literal ".Substring (Start,End)

Parameters

Start

Specifies the starting position of the substring. The index starts from 0.

End

Specifies the end position of the substring. The index starts from 0.

Description

SubstringMethod returnsStartTo the end (not includingEnd.

SubstringUsageStartAndEndThe smaller value of the two serves as the starting point of the substring. For example,Strvar.Substring (0, 3)AndStrvar.Substring (3, 0)Returns the same substring.

IfStartOrEndIsNanOr a negative number, replace it with 0.

The length of the substring is equalStartAndEndThe absolute value of the difference. For exampleStrvar.Substring (0, 3)AndStrvar.Substring (3, 0)The length of the returned substring is 3.

Example

The following example demonstratesSubstringMethod usage.

 
Function substringdemo (){VaR SS ;//Declare variables.VaR S = "The rain in Spain falls mainly in the plain ..";Ss =S. substring (12,17);//Returns the substring.Return (SS );//Returns a substring.
To be different from the substr () method:
1. substr returns the substring of the specified length starting from the specified position.
 
Substr Method

Returns a substring of the specified length starting from the specified position.

Stringvar.Substr (Start[,Length])

Parameters

Stringvar

Required. String text orStringObject.

Start

Required. The starting position of the required substring. The index of the first character in the string is 0.

Length

Optional. The number of characters to be included in the returned substring.

Description

IfLengthIf it is 0 or negative, an empty string is returned. If this parameter is not specified, the substring is extendedStringvar.

Example

The following example demonstratesSubstrMethod usage.

Function substrdemo () {var S, SS ;//Declare variables.VaR S = "The rain in Spain falls mainly in the plain .";
Ss =S. substr (12,5); // Obtain the substring.Return (SS );//Return"Spain".

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.