How to detect a string containing double-byte character?

  • in a column datatype in nvarchar

    how can i detect if the string contains any double-byte character such as Chinese, Japanese or Korean?

    Thanks~

  • Sounds like you need to use some ANSI searches to find those. What's your collation set as, BTW?

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • You could try comparing the nvarchar string to the string cast as varchar.

    DECLARE @str1 nvarchar(20)

    ,@str2 nvarchar(20)

    SELECT @str1 = N'AB' + NCHAR(12354) + N'CD'

    ,@str2 = N'ABCD'

    IF @str1 <> CAST(@str1 AS varchar(20))

    PRINT 'Str1 contains unicode character'

    ELSE

    PRINT 'Str1 contains no unicode'

    IF @str2 <> CAST(@str2 AS varchar(20))

    PRINT 'Str2 contains unicode character'

    ELSE

    PRINT 'Str2 contains no unicode'

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply