Trim Spaces in String - Ltrim Rtrim Not Working

Trim spaces in string - LTRIM RTRIM not working

I suspect, some non readable(Non-ascii characters) inside the name column, that might not get removed as part of TRIM calls.

select convert(varbinary, Name) from table

Reading the HEX output from above query should reveal the same.

Kindly read this to find how to write functions to remove such characters.

SQL Server RTRIM(LTRIM([City])) not stripping whitespace

Maybe the whitespace is not just a space:

Try this:

  UPDATE US_City_State
SET [City] = LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(REPLACE([City], CHAR(10), ''), CHAR(13), ''), CHAR(9), ''), CHAR(160), '')))

Explanation:
Some white space are not really space (' '). Here are some of the whitespace:

CHAR(9)     =   Horizontal Tab
CHAR(10) = Line Feed
CHAR(13) = Carriage Return
CHAR(160) = Non-Breaking Space

What I did is remove the above whitespaces. You can replace it by space(' ') or CHAR(32), depends on how you want to handle them.

SQL Server - RTRIM(LTRIM(column)) does not work

UN_DataIN == 0x45062706470631062920292029202920292029202000

So presuming Arabic your string ends with Unicode paragraph separators U+2029 and then a single whitespace all of which you need to remove;

select rtrim(replace(UN_DataIN, nchar(0x2029), '')) + '!'

ماهر!

LTRIM RTRIM not working for Chinese string SQL

The solution is to try trim the the character with the ASCII code 32. The following code works perfectly:

TRIM(CHAR(32) from [ShortText])

To check it out if works , I tried it this way :


DECLARE @t TABLE(txt nvarchar(255));
INSERT INTO @t VALUES (TRIM(CHAR(32) from '复合模头滤网 φ245 120目*300目 24×120目 '));

SELECT txt, LEN((txt)), ASCII(RIGHT(txt,1)) AS ASCII_Char
--32=SPACE,--13 CR,--11 LF, 9-tab
FROM @t

Mysql TRIM/RTRIM/REPLACE doesn't work to remove trailing spaces from an email column

I think you are facing this problem due to CHAR(10) in your text. Can you try removing it -

REPLACE(eb.tr_email, CHAR(10), '')

How to remove WhiteSpaces using LTRIM and RTRIM to display name?

use replace() function

select replace(name,' ','')


Related Topics



Leave a reply



Submit