Skip to content
Advertisement

LTRIM RTRIM not working for Chinese string SQL

I have a column named Text which receives from the end user the following string:

'复合模头滤网 φ245 120目*300目 24×120目 '

Which includes a weird space, kind of larger than the regular space, at the end. However it has the same ASCII code as the normal space 32.

I used this SQL code to trim my string but always returning same string without trimming !!!!

LTRIM(RTRIM([Text]))

Advertisement

Answer

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


User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement