TRIM

fun TRIM(column: KQLiteColumn<*>, trimChars: String? = null): KQLiteColumn<String>

Removes characters from the beginning and end of a string.

This function corresponds to the trim(X, Y) function in SQLite.

  • If only one argument column is provided, it removes leading and trailing spaces from the string.

  • If the optional trimChars argument is provided, it removes any character present in trimChars from both the beginning and the end of the string in column.

If the input column is not a string, it is first coerced into one. A NULL input results in a NULL output.

Example

// Removes leading and trailing spaces: trim('  hello  ') -> 'hello'
select(TRIM(StringLiteral(" hello "))).execute()

// Removes specified leading/trailing characters: trim('**--hello--**', '*-') -> 'hello'
select(TRIM(StringLiteral("**--hello--**"), "*-")).execute()

// Using a column
select(TRIM(Users.username)).from(Users)

Return

A KQLiteColumn of type String containing the trimmed string.

Author

MOHAMMAD AZIM ANSARI

Parameters

column

The column or string value from which to trim characters.

trimChars

An optional string containing the set of characters to remove. If null or omitted, spaces are trimmed.

See also