O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required