• 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: Adding spaces to an NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding spaces to an NSString


  • Subject: Re: Adding spaces to an NSString
  • From: "stephen joseph butler" <email@hidden>
  • Date: Tue, 18 Mar 2008 23:18:25 -0500

On Tue, Mar 18, 2008 at 11:10 PM, stephen joseph butler <
email@hidden> wrote:

> Yes; there's not a good, easy way to do this. One implementation that at
> first seems correct is this:
>
> from = [NSMutableString string];
> for (int i = 0; i < [to length]; ++i)
>   [from appendFormat:@"%C ", [from characterAtIndex:i]];
>
> That is, until you realize that unichar is 16 bit, and some "characters"
> are encoded as two unichar's. Opps! A better implementation, relying on the
> fact that NSString is UTF16 (I don't think endianess would matter here),
> would do this:
>
> from = [NSMutableString string];
> for (int i = 0; i < [to length]; ++i) {
>   unichar c = [from characterAtIndex:i];
>
>   if ((c >= 0xD800) && (c <= 0xDBFF))
>     [from appendFormat:@"%C", c];
>   else
>     [from appendFormat:@"%C ", c];
> }
>

Wow. I am more tired that I thought. Please use the right variable instead
of my horribly confusing "from" and "to". I hope you get the point anyway :)
_______________________________________________

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

  • Follow-Ups:
    • Re: Adding spaces to an NSString
      • From: "Ken Ferry" <email@hidden>
References: 
 >Adding spaces to an NSString (From: "J. Todd Slack" <email@hidden>)
 >Re: Adding spaces to an NSString (From: "stephen joseph butler" <email@hidden>)

  • Prev by Date: Re: Printing Page Orientation
  • Next by Date: Re: Breaking on console output?
  • Previous by thread: Re: Adding spaces to an NSString
  • Next by thread: Re: Adding spaces to an NSString
  • Index(es):
    • Date
    • Thread