Name

subString — Extract a substring from a string

Usage

String.subString(str, start, len)

str : String

start : Number

len : Number

Description

Returns a substring of str, starting at index start and continuing for len characters. The first character in the string has index zero.

If start is less than zero, it’s set to zero. If there are fewer than len characters in the string after start, all are returned. If start is past the end of the string, or len is less than or equal to zero, an empty string is returned. If start or len is a floating-point number, it’s first converted to an integer with Float.int( ).

Returns invalid if any of the arguments can’t be converted to the appropriate type.

Examples

String.subString("Example", 1, 2)

returns string "xa"

String.subString("Example", 4, 6)

returns string "ple"

String.subString("Example", -3, 1)

returns string "E"

String.subString("Example", 7, 2)

returns string ""

String.subString("Example", 3, -2)

returns string ""

String.subString("Example", 2.9, 3.8)

returns string "amp"

String.subString(12345, 2, 2)

returns string "34"

String.subString(false, 1, 3)

returns string "als"

String.subString(invalid, 4, 9)

returns invalid

String.subString("foo", "bar", 1)

returns invalid

String.subString("foo", 1, "bar")

returns invalid

Get Learning WML, and WMLScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.