aspnet , localization , csharp ,

Check if string is Arabic - C#

by Abhith Rajan FollowSeptember 06, 2017 · 2 min read · Last Updated:
Share this

I have pretty good experience in bilingual web app development, especially in English & Arabic languages. The challenge with switching website page from English to Arabic is not just the content translation, the whole layout need to be changed and the text direction for all need to be RTL where as for English it need to be LTR.

We developed this one app socialboard which aggregates content from social medias and displays in a single place. Initially, we focused only on English content so everything in LTR even though some aggregated content was in Arabic. But then we got some clients whose primary language is Arabic. i.e most of the content of their social media was in Arabic.

So we had to do some changes, UX team prepared the RTL layout for displaying content. The development team had to classify content (i.e to flag them isRTL or not) during creation and use proper layout based on isRTL field value of the content.

To classify, or to check whether the given content language is Arabic or not, we used the following extension method,

/// <summary>
/// To check whether the given string is Arabic.
/// </summary>
/// <param name="input"></param>
/// <returns>Returns True if Arabic</returns>
public static bool IsRtl(this string input)
{
    return Regex.IsMatch(input, @"\p{IsArabic}");
}

And it is now part of my Code.Library package ValidationHelper module.

If you know any better way to check if the string is Arabic in C#, let me know in the comments.

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub

Abhith Rajan

Written by Abhith Rajan FollowBuy me a coffee
Abhith Rajan is an aspiring software engineer with more than 6 years of experience and proven successful track record of delivering technology-based products and services.

Related Services

SmarterASP.net - Unlimited ASP.NET Web Hosting

ASP.NET Hosting by SmarterASP.net. Unlimited ASP.NET Hosting Plans Starting at $2.95 a month.