boot4life
boot4life

Reputation: 5324

What characters do LTRIM and RTRIM trim exactly?

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

Upvotes: 3

Views: 332

Answers (1)

HABO
HABO

Reputation: 15841

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.)

Upvotes: 5

Related Questions