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 MethodReturns a substring of the specified length starting from the specified position.
Stringvar.Substr (Start[,Length])
ParametersStringvar
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.
DescriptionIfLengthIf it is 0 or negative, an empty string is returned. If this parameter is not specified, the substring is extendedStringvar.
ExampleThe 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"
.