Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:08:08+00:00 2026-06-04T21:08:08+00:00

I am displaying user comments in two UILabels – one for the username and

  • 0

I am displaying user comments in two UILabels – one for the username and one for the message. Both labels have the same X,Y coordinate, but the message label is prepended with spaces equaling the width of the username. This technique helps me easily support multiline messages.

A problem arises when users write Arabic messages. Arabic is a right to left language. This means, I must add spaces to the end of an Arabic string, not the beginning. As you can see in the screenshot below, I didn’t make that distinction and the Arabic message ran into the username. So how do I detect that the text property (NSString) of a UILabel was written in a right-to-left language?

arabic

Fail attempt 1: Regex

I’ve tried using regexes, but the following function always returns false for every string, including Arabic.

@implementation UILabel (position)

- (BOOL) containsArabic
{
    NSError* error;
    NSRegularExpression* regex = [NSRegularExpression
        regularExpressionWithPattern:@"\p{Arabic}" 
        options:0
        error:&error
    ];
    return error == nil 
        && [regex 
            numberOfMatchesInString:self.text 
            options:0 
            range:NSMakeRange(0, self.text.length)] > 0;
}

@end

Fail attempt 2: NSLocale

- (BOOL) containsArabic
{
    NSString *isoLangCode = (NSString*)CFStringTokenizerCopyBestStringLanguage(
       (CFStringRef)self.text, 
       CFRangeMake(
           0, 
           self.text.length
       )
    );
    NSLocaleLanguageDirection direction = [NSLocale lineDirectionForLanguage:isoLangCode];
    NSLog(@"++++++");
    NSLog(@"%@", self.text);
    NSLog(@"%d", direction);
    return direction == NSLocaleLanguageDirectionRightToLeft;
}

Output is useless:

2012-05-28 10:59:11.454 [2110:707] MANCHESTER CITY VS MANCHESTER UNITED LIVE HD
2012-05-28 10:59:11.461 [2110:707] 0
2012-05-28 10:59:11.474 [2110:707] ++++++
2012-05-28 10:59:11.477 [2110:707] tak
2012-05-28 10:59:11.484 [2110:707] 0
2012-05-28 10:59:11.511 [2110:707] ++++++
2012-05-28 10:59:11.513 [2110:707] ونهارك سعيد
2012-05-28 10:59:11.520 [2110:707] 3
2012-05-28 10:59:11.704 [2110:707] ++++++
2012-05-28 10:59:11.712 [2110:707] نهارك سعيد
2012-05-28 10:59:11.740 [2110:707] 3
2012-05-28 10:59:11.763 [2110:707] ++++++
2012-05-28 10:59:11.767 [2110:707] i think i am close
2012-05-28 10:59:11.772 [2110:707] 3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:08:09+00:00Added an answer on June 4, 2026 at 9:08 pm

    This answer assumes that you are using ARC:

    NSString *stringToTest = @"Some Foreign Language";
    
    NSString *isoLangCode = (__bridge_transfer NSString*)CFStringTokenizerCopyBestStringLanguage((__bridge CFStringRef)stringToTest, CFRangeMake(0, stringToTest.length));
    
    NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLangauge:isoLangCode];
    

    You can then use the NSLocale API’s lineDirectionForLanguage: method to determine the languages line direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of user comments stored in a database and I'm displaying
Displaying Spring Dropdown in JSP if user does NOT have value in it.. I
I have an EditText displaying a user defined text label. It displays as blue
Before displaying user posts I run them though Sanitize::html() to escape all html. But
i have php while loop, creates many classes, displaying info (user posts ect) and
I have a web app that has a list of user comments. I want
I'm displaying user avatar images on a MapView. The avatars appear to be working
I'm displaying user messages through templates using RequestContext in Django, which gives access to
In my app are activities which are displaying user sensitive data (inbox, passwords, bank
Displaying Type here to ... until the user enters text into a TextBox is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.