none
how do i check whether my string contains arabic characters or not? RRS feed

Answers

  • Try this:

        public static bool HasArabicGlyphs(string text) {
          char[] glyphs = text.ToCharArray();
          foreach (char glyph in glyphs) {
            if (glyph >= 0x600 && glyph <= 0x6ff) return true;
            if (glyph >= 0x750 && glyph <= 0x77f) return true;
            if (glyph >= 0xfb50 && glyph <= 0xfc3f) return true;
            if (glyph >= 0xfe70 && glyph <= 0xfefc) return true;
          }
          return false;
        }


    Hans Passant.
    Thursday, August 21, 2008 9:46 AM
    Moderator

All replies

  • Try this:

        public static bool HasArabicGlyphs(string text) {
          char[] glyphs = text.ToCharArray();
          foreach (char glyph in glyphs) {
            if (glyph >= 0x600 && glyph <= 0x6ff) return true;
            if (glyph >= 0x750 && glyph <= 0x77f) return true;
            if (glyph >= 0xfb50 && glyph <= 0xfc3f) return true;
            if (glyph >= 0xfe70 && glyph <= 0xfefc) return true;
          }
          return false;
        }


    Hans Passant.
    Thursday, August 21, 2008 9:46 AM
    Moderator
  • Thanks for your help...It working now...
    Friday, August 22, 2008 7:03 AM
  • internal bool HasArabicCharacters(string text)
    {
      Regex regex = new Regex(
        "[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");
      return regex.IsMatch(text);
    }
    You can use the above method to check for Arabic characters using Regular Expressions.
    Makhaly_cs
    Tuesday, July 6, 2010 8:19 AM
  • The best you're going to get is going to be the various RegEx unicode block character class: \p{name}

    Regex.IsMatch(str[1], @"\p{IsArabic}");
    Thursday, October 2, 2014 7:58 AM
  • //Try this one
    public static bool HasArabicCharacter(string input)
    {
      System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");
      return regex.IsMatch(input);
    }

    • Edited by Sohail_Ahmad Wednesday, February 7, 2018 10:00 AM Code Formatted.
    Wednesday, February 7, 2018 9:58 AM