String.substring()
Signature
String substring (String s1, int beginIndex, int endIndex)
Description
Returns a new string that is a substring of this string. The substring
begins at the specified beginIndex and extends to the character at index
endIndex - 1
. Thus the length of the substring is
endIndex - beginIndex
.
Parameters
Name | Type | Description |
s1 | String | A String to use as a source of the substring. |
beginIndex | int | The String index where the substring should start. The index is zero-based. |
endIndex | int | The String index where the substring should end. The index is zero-based. |
Returns
Type | Description |
String | A new string that is a substring of this string starting
at beginIndex and continuing to endIndex . |
Example
String result = String.substring ("This is a test", 5, 9);
Result is:
result contains: "is a"