• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to check the capital letter?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to check the capital letter?


  • Subject: Re: How to check the capital letter?
  • From: Ron Fleckner <email@hidden>
  • Date: Mon, 11 Aug 2008 23:59:53 +1000


On 11/08/2008, at 11:54 PM, Uli Kusterer wrote:

On 11.08.2008, at 15:29, Ron Fleckner wrote:
NSString *str = @"Aa";
char first = [str characterAtIndex:0];
char second = [str characterAtIndex:1];
NSLog(@"%c is %@.", first, isupper(first) ? @"uppercase" : @"lowercase");
NSLog(@"%c is %@.", second, isupper(second) ? @"uppercase" : @"lowercase");


Result:

	A is uppercase.
	a is lowercase.

Bad Idea (tm):

You're discarding the high byte of the unichar that characterAtIndex: returns by casting it to a regular char, so isupper() might get to see a completely different character than the user sees.

Second, Unicode can have decomposed character sequences, so the glyph at that particular index may actually be several characters long, and you're only analyzing the first one.

NSCharacterSet is probably your best bet. You could check whether whatever character you're looking at is a member of the uppercaseLetterCharacterSet.

Cheers,
-- Uli Kusterer

OK, thanks Uli and Jean-Daniel. I see why it's not such a good idea.

Ron
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How to check the capital letter? (From: Macarov Anatoli <email@hidden>)
 >Re: How to check the capital letter? (From: Ron Fleckner <email@hidden>)
 >Re: How to check the capital letter? (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: How to check the capital letter?
  • Next by Date: NSConditionLock vs MPQueue
  • Previous by thread: Re: How to check the capital letter?
  • Next by thread: Re: How to check the capital letter?
  • Index(es):
    • Date
    • Thread