w3resource

SQLite trim() function

Description

SQLite TRIM() function returns a string after removing all prefixes or suffixes specified in the argument from the given string.

Syntax:

trim(X);
trim(X,Y);

SQLite Version: 3.8.5

Arguments:

Name Description
X The string from which the remove action will happen.
Y The character(s) set which will be removed from the string X.

If the Y argument is omitted, trim(X) removes spaces from both ends of X.

Example-1: SQLite trim() function

The following SQLite statement returns the string after removing the leading and trailing spaces from the given string ' trim '.

SELECT 'Before'||'  trim  '||'After','Before'||trim('  trim  ')||'After'; 

Here is the result.

Sample Output:

'Before'||'  trim  '||'After'  'Before'||trim('  trim  ')||'After'
-----------------------------  -----------------------------------
Before  trim  After            BeforetrimAfter

In the above example, the first column shows that the string ' trim ' appeared with leading and trailing spaces, but in the second column as we have used the trim() with the string ' trim ', so it removes all the leading and trailing spaces from the string. Here to get better understand we have concat the string ' trim ' with 'Before' and 'After' strings.

Example-2: SQLite trim() function to remove leading or trailing character(s)

The following SQLite statement returns the string after removing the leading and trailing character(s) 'ma' from the given string 'madam'.

SELECT 'madam',trim('madam','ma'); 

Here is the result.

Sample Output:

'madam'     trim('madam','ma')
----------  ------------------
madam       d

In the above example, it shows that, the character set 'ma' have been removed from the given string 'madam' and the remaining character(s) returns. The search starting from the left.

Previous: substr()
Next: typeof()



Follow us on Facebook and Twitter for latest update.