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

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 06, 2010 8:19 AM