Namespace: String

Phaser.Utils. String

Methods


<static> Format(string, values)

Takes a string and replaces instances of markers with values in the given array. The markers take the form of %1, %2, etc. I.e.:

Format("The %1 is worth %2 gold", [ 'Sword', 500 ])

Parameters:
Name Type Description
string string

The string containing the replacement markers.

values array

An array containing values that will replace the markers. If no value exists an empty string is inserted instead.

Since: 3.0.0
Source: src/utils/string/Format.js (Line 7)
Returns:

The string containing replaced values.

Type
string

<static> Pad(str [, len] [, pad] [, dir])

Takes the given string and pads it out, to the length required, using the character specified. For example if you need a string to be 6 characters long, you can call:

pad('bob', 6, '-', 2)

This would return: bob--- as it has padded it out to 6 characters, using the - on the right.

You can also use it to pad numbers (they are always returned as strings):

pad(512, 6, '0', 1)

Would return: 000512 with the string padded to the left.

If you don't specify a direction it'll pad to both sides:

pad('c64', 7, '*')

Would return: **c64**

Parameters:
Name Type Argument Default Description
str string

The target string. toString() will be called on the string, which means you can also pass in common data types like numbers.

len integer <optional>
0

The number of characters to be added.

pad string <optional>
" "

The string to pad it out with (defaults to a space).

dir integer <optional>
3

The direction dir = 1 (left), 2 (right), 3 (both).

Since: 3.0.0
Source: src/utils/string/Pad.js (Line 7)
Returns:

The padded string.

Type
string

<static> Reverse(string)

Takes the given string and reverses it, returning the reversed string. For example if given the string Atari 520ST it would return TS025 iratA.

Parameters:
Name Type Description
string string

The string to be reversed.

Since: 3.0.0
Source: src/utils/string/Reverse.js (Line 7)
Returns:

The reversed string.

Type
string

<static> UppercaseFirst(str)

Capitalizes the first letter of a string if there is one.

Parameters:
Name Type Description
str string

The string to capitalize.

Since: 3.0.0
Source: src/utils/string/UppercaseFirst.js (Line 7)
Returns:

A new string, same as the first, but with the first letter capitalized.

Type
string
Examples
UppercaseFirst('abc');
// returns 'Abc'
UppercaseFirst('the happy family');
// returns 'The happy family'
UppercaseFirst('');
// returns ''

<static> UUID()

Creates and returns an RFC4122 version 4 compliant UUID.

The string is in the form: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where each x is replaced with a random hexadecimal digit from 0 to f, and y is replaced with a random hexadecimal digit from 8 to b.

Since: 3.12.0
Source: src/utils/string/UUID.js (Line 7)
Returns:

The UUID string.

Type
string