Reputation: 31739
I am not sure why but TRIM()
or RTRIM()
not working for me.
SELECT TRIM('YV4.3x2.8SA-2 ');
is returning 'YV4.3x2.8SA-2 '
.
I can not remove all the spaces as the string may contain space in between.
Upvotes: 1
Views: 2346
Reputation: 116448
So, that last character is 0xC2A0
, not 0x20
(space). That is UTF-8 encoding for Unicode code point U+00A0, also known as a non-breaking space.
To remove these using TRIM()
, pass convert(0xC2A0 using utf8mb4)
for remstr
:
select TRIM(convert(0xC2A0 using utf8mb4) FROM 'YV4.3x2.8SA-2 ');
If you potentially have a mix of these characters and spaces, the easiest method to remove both would be to first replace the NBSP's with regular spaces, then pass the result through TRIM()
:
select TRIM(REPLACE('YV4.3x2.8SA-2 ', convert(0xC2A0 using utf8mb4), ' '));
(SQL Fiddle demo, with a mix of spaces thrown in)
Upvotes: 7