SHIP:Sail:subStr

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

SHIP Sail Home

SHIP Sail Function Home

subStr

Returns the N-character substring of a string starting at an index

Prototype

String subStr(String s, Integer index);

String subStr(String s, Integer index, Integer length);

Parameters/Return Value

Parameter Data Type Description
s String Original string
index Integer Starting index (0 is the first character in a string)
length Integer number of characters to get
Return String the substring requested

Detailed Description

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

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

  • the original string has no length
  • the index specified is beyond the end of the original string
  • the length parameter is zero

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

If the length is negative or unspecified, all characters in the original string from the index onwards will be returned.

Examples

Example Result Notes
subStr ("hello", 1); "ello" unspecified length means return the rest of the string
subStr ("hello", 0, 1); "h"
subStr ("hello", 1, -1); "ello" -1 for length returns the rest of the string
subStr ("hello", 10, 2); "" index is beyond the length of the original string
subStr ("hello", -1, 2); "he" index negative is the same as index 0
subStr ("hello", 3, 0); "" zero length always returns an empty string
length(""); 0
length("™"); 1 ™ is three bytes in UTF-8 but is only one character