locked
How to check whether nchar columns Arabic Character Set? RRS feed

  • Question

  • Hi

     

    How can I check whether an nchar column contains Arabic character set? The only allowed values that can go into this column are English and Arabic.

     

     

    Thanks,

    Salman Shehbaz.

    Wednesday, March 5, 2008 7:43 AM

Answers

  • Here it is,

    Code Snippet

    create function IsArabicCharSet(@Word Nvarchar(100))

    returns int

    as

    begin

      Declare @Chars Table (Letter int);

      Declare @count as int;

      Set @count = 0;

     

      While len(@Word) > 0

      Begin

        Insert Into @Chars

        Values(Unicode(Substring(@Word,1,1)));

     

        Set @Word = Substring(@Word,2,Len(@Word)-1);

      End

     

      Select @count = Count(*) from @Chars

      Where

        Letter Between 0x0620 And 0x06FF

     

      return @count

    End

     

    go

     

    select case when 0 <> dbo.IsArabicCharSet(N'علوم وتكنولوجيا') then 'Yes' Else 'No' End

     

    select case when 0 <> dbo.IsArabicCharSet(N'ABCD') then 'Yes' Else 'No' End

     

     

     

    Wednesday, March 5, 2008 11:53 AM
  • If you want to accept both arabic & english change the following condition on the function...

     

    Letter Between 0x0620 And 0x06FF

    or

    Letter Between 0x0000 And 0x00FF

     

    Wednesday, March 5, 2008 11:56 AM

All replies

  • Here it is,

    Code Snippet

    create function IsArabicCharSet(@Word Nvarchar(100))

    returns int

    as

    begin

      Declare @Chars Table (Letter int);

      Declare @count as int;

      Set @count = 0;

     

      While len(@Word) > 0

      Begin

        Insert Into @Chars

        Values(Unicode(Substring(@Word,1,1)));

     

        Set @Word = Substring(@Word,2,Len(@Word)-1);

      End

     

      Select @count = Count(*) from @Chars

      Where

        Letter Between 0x0620 And 0x06FF

     

      return @count

    End

     

    go

     

    select case when 0 <> dbo.IsArabicCharSet(N'علوم وتكنولوجيا') then 'Yes' Else 'No' End

     

    select case when 0 <> dbo.IsArabicCharSet(N'ABCD') then 'Yes' Else 'No' End

     

     

     

    Wednesday, March 5, 2008 11:53 AM
  • If you want to accept both arabic & english change the following condition on the function...

     

    Letter Between 0x0620 And 0x06FF

    or

    Letter Between 0x0000 And 0x00FF

     

    Wednesday, March 5, 2008 11:56 AM