{ltrim:string:chars}

Description

Removes characters from the LEFT (the beginning) of a string. ltrim is the left-only counterpart of rtrim (right only) and trim (both ends), and it is the raw PHP ltrim. The second argument, chars, lists which characters to strip. It is a SET of single characters, not a prefix: ltrim removes any of those characters one at a time from the start until it meets a character that is not in the set. PHP range syntax such as a..z is allowed inside chars. Important trap: unlike trim, ltrim does NOT default to stripping whitespace. When you give no chars argument the set is empty and ltrim strips nothing, so the string comes back unchanged. To remove leading spaces you must pass a space (or the characters you want) as chars. Because AA does not pre-trim ltrim's arguments, the leading whitespace of the input is preserved for ltrim to act on. ltrim works on bytes and is not multibyte aware, so use it with ASCII character sets; for whitespace on both ends prefer trim, which is UTF aware.

Parameters

string required default (empty)

The text to trim. Characters are removed from its left end. AA does not pre-trim this value, so any leading whitespace is kept and is available for ltrim to strip when chars asks for it.

chars optional default (empty - strips nothing)

The set of single characters to strip from the left, given one after another with no separator (for example 0 for zeros, a space for spaces, .,; for those three punctuation marks). It is a character set, not a prefix string. PHP range syntax like a..z is allowed. When chars is omitted the set is empty and ltrim strips nothing, returning the string unchanged - pass a space to remove leading spaces.

Examples

test{ltrim:0042:0}
Expected42
Actual42
The most common use: drop leading zeros from a number-like string. chars is 0, so every leading 0 is removed and the rest is kept.
test{ltrim:xxhello:x}
Expectedhello
Actualhello
chars is x, so the run of leading x characters is removed. Trailing or inner x characters are untouched - ltrim only works on the left.
test[{ltrim: indented line: }]
Expected[indented line]
Actual[indented line]
To remove leading spaces you must put a space in chars (here the character right after the second colon is a space). The square brackets are only there to make the trimmed result visible.
test[{ltrim: indented line}]
Expected[ indented line]
Actual[ indented line]
Unlike trim, ltrim with no chars argument strips nothing: the set is empty so the leading spaces survive. The brackets show the spaces are still there. Use trim, or pass a space, when you want them gone.
test{ltrim:Mr. Smith:Mr. }
ExpectedSmith
ActualSmith
chars here is the four-character set M, r, dot and space. ltrim peels those off the left one by one - M, r, dot, space - and stops at S. It is not matching the word "Mr. " as a whole; any of those characters anywhere in the leading run would be removed.
test{ltrim:a1b2c3:a..z}
Expected1b2c3
Actual1b2c3
PHP range syntax works inside chars: a..z is every lowercase letter. The leading a is removed and ltrim stops at 1, which is not a letter.