Numbers & Text > Text


Conversion

Convert to Text

object as text

Converts the given value to text.

("" + [VALUE])

Constants

Empty Text

empty text

Returns an empty text ("").

""

Space

space

Returns a space (" ").

" "

Operations

Text Length

text length

Returns the number of characters in the given text.

[TEXT].length

Combine Text

text & text

Combines the two given pieces of text into one and returns that result.

[TEXT] + [TEXT]

Trim Text

trim whitespace from text

Removes spaces from the beginning and the end of the given text and returns that result. (When given an attribute, the value of the attribute remains unchanged.)

StringTools.trim([TEXT])

Comparison

Equals (Text)

object = object

Returns true if both pieces of text are exactly the same.

([TEXT] == [TEXT])

Is Text Empty?

text is empty

Returns true if the length of the given text is 0.

([TEXT] == "")

Does Text come before/after?

before-block after-block

Returns true if the first given text alphabetically comes before (or after) the second given text.

//A comes BEFORE B
strCompare([TEXT], [TEXT], -1);

//A comes AFTER B
strCompare([TEXT], [TEXT], 1);

Find / Replace

Find Character

character at position int in text

Returns the character at the given position. Note that the first index in a text is 0, not 1. Throws a runtime error if the given position is out of bounds.

[TEXT].charAt([INT])

Get Text Position

index of text in text

Returns the index at which the given phrase (or character) appears in the given text. Returns -1 if the phrase is not found.

Example: The word "dog" corresponds to these indices: d = 0, o = 1 and g = 2. If you selected the letters "og" from the word "dog" (enter "og" in the field on the left and "dog" in the field on the right), the result would be 1.

[TEXT].indexOf([TEXT])

Replace Text in Text

replace text with text in text

Replaces one phrase with another within the given text.

Example:
replace-example
Returns cheeseburger

StringTools.replace([TEXT], [TEXT], [TEXT])

Substring (Part of Text)

part of text start int end int

Returns part of the given text, given the starting and ending indices. More specifically, this block returns the characters beginning with the start index and ending with one less than the ending index.

Example: The word "cats" corresponds to these indices: c = 0, a = 1, t = 2, s = 3. If you enter "cats" in the field on the left, and 1, 3 as your starting and ending index numbers, the block would return the letters "at", i.e. the letters that correspond to the index numbers 1 and 2 in the word "cats."

[TEXT].substring([INT], [INT])

Case

Get Text in Upper/Lower Case

uppercase-block lowercase-block

Returns the given text in all uppercase (or lowercase).

[TEXT].toUpperCase()
[TEXT].toLowerCase()

Split

Split into Words

split text into words

Splits the given text up into a list, using space as the separator (delimiter).

[TEXT].split(" ")

Split using Separator

split text using separator text

Splits the given text up into a list, using the given separator (delimiter) text.

[TEXT].split([TEXT])

Fonts

Get Width of Text using Font

get width for text using font

Returns the width of the given text using the given font. Useful for calculating positions for drawing text.

[FONT].font.getTextWidth([TEXT], [FONT].letterSpacing)/Engine.SCALE

Get Height of Font

get height using font

Returns the height of the given font. Useful for calculating positions for drawing text.

[FONT].getHeight()/Engine.SCALE