Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord
Namespace: String
Phaser.Utils.String
Source: src/utils/string/index.js (Line 7)

Methods

<static> Format(string, values)
Focus
Focus

Description:

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.

Returns:
Description:

The string containing replaced values.

Type:
  • string
Examples:
Since: 3.0.0
Source: src/utils/string/Format.js (Line 7)
Focus
Focus
<static> Pad(str, [len], [pad], [dir])
Focus
Focus

Description:

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 arguments Default description
str string | number | object

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

len number <optional> 0

The number of characters to be added.

pad string <optional> " "

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

dir number <optional> 3

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

Returns:
Description:

The padded string.

Type:
  • string
Examples:
Since: 3.0.0
Source: src/utils/string/Pad.js (Line 7)
Focus
Focus
<static> RemoveAt(string, index)
Focus
Focus

Description:

Takes a string and removes the character at the given index.

Parameters:

name type description
string string

The string to be worked on.

index number

The index of the character to be removed.

Returns:
Description:

The modified string.

Type:
  • string
Examples:
Since: 3.50.0
Focus
Focus
<static> Reverse(string)
Focus
Focus

Description:

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.

Returns:
Description:

The reversed string.

Type:
  • string
Examples:
Since: 3.0.0
Focus
Focus
<static> UppercaseFirst(str)
Focus
Focus

Description:

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

Parameters:

name type description
str string

The string to capitalize.

Returns:
Description:

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 ''
Since: 3.0.0
Focus
Focus
<static> UUID()
Focus
Focus

Description:

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.

Returns:
Description:

The UUID string.

Type:
  • string
Examples:
Since: 3.12.0
Source: src/utils/string/UUID.js (Line 7)
Focus
Focus