What characters do LTRIM and RTRIM trim exactly?

2019-02-24 12:27发布

问题:

LTRIM and RTRIM are documented to trim "blanks". What characters are considered "blank" exactly?

回答1:

Good question. Although there are many whitespace characters defined in Unicode, only a space (0x0020) is removed:

with Characters as (
  select NChar( 0 ) as Character
  union all
  select NChar( Unicode( Character ) + 1 )
    from Characters
    where Unicode( Character ) < 65535 ),
  CharacterMap as (
  select Unicode( Character ) as [UnicodePoint], Character,
    1 - Len( LTrim( Character ) ) as [Whitespace]
    from Characters )
  select UnicodePoint, Character, Whitespace
    from CharacterMap
    where Whitespace = 1
    option ( MaxRecursion 0 );

(The same applies to RTrim.)