Skip to content
Titanium SDK
Version12.6.4

You are reading 12.6.4. See this page in 13.4.1.

Global.String

moduleAndroidiPhoneiPadmacOS

The JavaScript built-in String type.

This module contains Titanium-only extensions for formatting data into locale-specific strings. The target locale is configured by the user in the device's system Settings.

Methods 5

Formats a string using printf-style substitution.

The format string follows the IEEE printf specification.

For each "conversion specification" (ie. %s for a string or %d for a number) used inside the string, formatString argument, the respective value is substituted from the argument list. For example:

var forename = 'Paul';
var number = 21;
var message = String.format('Welcome, %s! You are visitor number %d', forename, number);
Ti.API.info(message);
Parameters
ParametersTypeDescription
formatStringString

An IEEE printf-style string, containing zero or more conversion specifications.

valueString | Number

Values to substitute into the formatString. The method expects a variable number of value arguments, one for each % conversion specification in the format string. Optional on Android.

Returns String

Formatted string.

Formats a number into the currency format, including currency symbol, of the locale configured for the system.

Parameters
ParametersTypeDescription
valueNumber

Currency value.

Returns String

Formatted, localized string.

Formats a date into the date format of the locale configured for the system.

Parameters
ParametersTypeDescription
dateDate

Date to format.

format?String

Date format to use. One of 'short', 'medium', 'long' or 'full'.

Returns String

Formatted, localized string.

Formats a number into the decimal format, including decimal symbol, of the locale configured for the system.

The localized string created by this method can be parsed be parsed back to a number via the Titanium.Locale.parseDecimal method.

Parameters
ParametersTypeDescription
valueNumber

Value to format.

locale?String

Locale string. For example, en-US for US English.

pattern?String

Format pattern.

Returns String

String representation of the specified number, using a locale-specific decimal symbol, if required.

Formats a date into the time format of the locale configured for the system.

On Android, this method returns the short format.

Parameters
ParametersTypeDescription
dateDate

Date to format.

format?String

Date format to use. One of 'short', 'medium', or 'long' (iOS only.)

Returns String

Formatted, localized string.