TRIM to remove Prefix and Suffix from a string


MySQL Trim
SELECT TRIM( BOTH 'XX' FROM 'XXplus2net.comXXX')// Output plus2net.comX
Arguments
BOTH
Remove matching string from trailing and leading part of the string
LEADING
Remove matching string from leading part of the string
TRAILING
Remove matching string from trailing part of the string
SELECT TRIM(BOTH 'XX' FROM 'XX.plus2net.com.XXX')// Output .plus2net.com.X
SELECT TRIM(LEADING 'www.' FROM 'www.plus2net.com')// Output plus2net.com
SELECT TRIM(LEADING 'XX' FROM 'XX.plus2net.com.XXX') // Output .plus2net.com.XXX
SELECT TRIM(TRAILING 'com' FROM 'plus2net.com')// Output plus2net.
SELECT TRIM(TRAILING 'XX' FROM 'XX.plus2net.com.XXX') // Output XX.plus2net.com.X
Without using any arguments we can remove blank space from both ends of the string.
SELECT TRIM(' plus2net.com ') // Output is plus2net.com

Case in sensitive replacement

TRIM is a case sensitive match and replacement function.
SELECT TRIM(BOTH 'XX' FROM 'xx.plus2net.com.XXX')// Output xx.plus2net.com.X
To make it case in sensitive function we will use LOWER or UPPER case functions.
SELECT TRIM(BOTH UPPER('XX') FROM UPPER('xx.plus2net.com.XXX')) // Output  .PLUS2NET.COM.X
By using LOWER
SELECT TRIM(BOTH LOWER('XX') FROM LOWER('xx.plus2net.com.XXX')) // Output .plus2net.com.x 

SQL String References LTRIM() : Removing space from LEFT RTRIM() : Removing space from RIGHT of the string

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com

    18-12-2023

    SELECT TRIM(BOTH LOWER('X.mcoX') FROM LOWER('xx.plus2net.com.XXX')) // Output plus2net




    SQL Video Tutorials










    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer