• 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: AM/PM letter UNICODE issues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AM/PM letter UNICODE issues


  • Subject: Re: AM/PM letter UNICODE issues
  • From: Todd Dombrowski <email@hidden>
  • Date: Mon, 18 Oct 2010 17:19:44 -0700

Here's one way to accomplish your stated goal:

-- BEGIN CODE --
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // NSDateFormatter, locale friendly
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateStyle:NSDateFormatterNoStyle];
    [df setTimeStyle:NSDateFormatterShortStyle];
    // Get time from date
    NSString *timeString = [df stringFromDate:[NSDate date]];
    [df release];

    CFShow(timeString);

    // Abbreviate time: "10:00 AM" to "10:00a"
    NSString *abbreviateTimeString = [NSString stringWithString:timeString];
    abbreviateTimeString = [timeString
stringByReplacingOccurrencesOfString:@" AM" withString:@"a"];
    abbreviateTimeString = [timeString
stringByReplacingOccurrencesOfString:@" PM" withString:@"p"];

    CFShow(abbreviateTimeString);

    [pool drain];
    return 0;
}
-- END CODE --

of course if you are on iOS 4.0 or later, you can play with the new
regex classes and add 30 more lines of code ;-)

Todd Dombrowski
pzlbox, llc

On Mon, Oct 18, 2010 at 10:19 AM, Alex Kac <email@hidden> wrote:
>
> I'm fairly certain my problem here is that I wasn't thinking about unicode terms here.
>
> What we are trying to do:
> Shorten the AM/PM to just the first character in Western Languages so that a time is shown as "1:30a".
>
>        NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
>        NSString* am = [[[formatter AMSymbol] substringToIndex:1] lowercaseString];
>        NSString* pm = [[[formatter PMSymbol] substringToIndex:1] lowercaseString];
>
>
> This works in Western languages just fine. However in languages like Korean it does not work giving a random character seemingly. From reading on this list over time I believe its because I'm just getting one part of a multi-part character (I'm no good with unicode terms sorry).
>
> My guess is I need to use rangeOfComposedCharacterSequenceAtIndex and then get the range and use a substring with that range. But I'm not sure since my knowledge here is pretty limited. Would love some direction. Thanks!_______________________________________________
>
> 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
_______________________________________________

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: 
 >AM/PM letter UNICODE issues (From: Alex Kac <email@hidden>)

  • Prev by Date: Re: Framework Major versions
  • Next by Date: Re: Return key should enter return in textfield and not press default button
  • Previous by thread: Re: AM/PM letter UNICODE issues
  • Next by thread: Re: AM/PM letter UNICODE issues
  • Index(es):
    • Date
    • Thread