Trim() / LTrim() / RTrim() [AHK_L 31+]

Trims characters from the beginning and/or end of a string.

NewString :=  Trim(String , OmitChars)
NewString := LTrim(String , OmitChars)
NewString := RTrim(String , OmitChars)

Parameters

String

Any string value or variable. Numbers are not supported.

OmitChars

If omitted, spaces and tabs will be removed. Otherwise, specify a list of characters (case-sensitive) to exclude from the beginning and/or end of String.

Return Value

These functions return the trimmed version of the specified string.

Examples

Trims all spaces from the left and right side of a string.

text := "  text  "
MsgBox % "No trim:`t '" text "'"
    . "`nTrim:`t '" Trim(text) "'"
    . "`nLTrim:`t '" LTrim(text) "'"
    . "`nRTrim:`t '" RTrim(text) "'"

Trims all zeros from the left side of a string.

MsgBox % LTrim("00000123", "0")