aspnet | localization | c-sharp

Check if string is Arabic - C#

by Abhith RajanSeptember 06, 2017 · 2 min read · Last Updated:

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 needs to be changed and the text direction for all need to be RTL whereas for English it needs to be LTR.

We developed this one app socialboard which aggregates content from social media 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, the 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,

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

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.

Abhith Rajan

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

Was this article helpful?

Your opinion matters

Please share your thought about this article

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

Related Posts

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.