SHIP:Sail:subString

From Serious Documentation
Revision as of 10:49, 6 December 2012 by Admin (talk | contribs) (Created page with "__NOTOC__ SHIP Sail Home SHIP Sail Function Home == subString== Returns the substring of a string starting at an index and ending at an ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SHIP Sail Home

SHIP Sail Function Home

subString

Returns the substring of a string starting at an index and ending at an index

Prototype

String subString(String s, Integer start);

String subString(String s, Integer start, Integer end);

Parameters/Return Value

Parameter Data Type Description
s String Original string
start Integer Starting index (0 is the first character in a string)
end Integer Ending index (inclusive)
Return String the substring requested

Detailed Description

The subString() function returns a number characters from within in a string, starting at a specified offset and ending at a specified offset.

Both the character at the starting and ending offset will be included in the result.

The resulting string will be empty (zero length) if any of the following conditions are true:

  • the original string has no length
  • the start index specified is beyond the end of the original string
  • the end index is less than the start index

If the start index is negative, an offset of 0 will be used.

If the end index is unspecified, all characters in the original string from the start index onwards will be returned.

Examples

Example Result Notes
subString("hello", 1); "ello" unspecified length means return the rest of the string
subString("hello", 0, 1); "he"
subString("hello", 0, 0); "h"
subString("hello", 1, -1); "" end index is less than start index
subString("hello", 10, 2); "" start index is beyond the length of the original string
subString("hello", -1, 1); "he" start index negative is the same as start index 0