SQL Sever string Intercept kanji

Source: Internet
Author: User

Recently, we need to intercept Chinese characters in a SQL string, use Unicode functions to determine the Unicode encoding of characters, and filter out non-Chinese characters according to the encoding range.

Wrote a function.

/* @str need to get a string of Kanji */

Create function Charrep (@str nvarchar (200))

Returns nvarchar (200)

As
Begin
DECLARE @i int, @char nvarchar (1), @zh nvarchar (200)
Set @i = 1
Set @zh = ' '
While @i <= Len (@str)
Begin
Set @char = substring (@str, @i, 1)
If Unicode (@char) between 19968 and 40869
Set @zh = @zh + @char
Set @i = @i + 1
End
Return @zh
End

Executes select dbo. Charrep (' Lennon good A/BC Lennon good ')

Result A/BC

Report:

Unicode encoding Range:
Kanji: [0x4e00,0x9fa5] (or decimal [19968,40869])
Number: [0x30,0x39] (or decimal [48, 57]) search
lowercase letters: [0x61,0x7a] (or decimal [97, 122])
Capital letters: [0X41,0X5A] (or decimal [65, 90])

SQL Sever string Intercept kanji

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.