Re: Adding spaces to an NSString

2008-03-19 Thread Ken Ferry
This is probably not sufficient. The string @"é" can be represented by two characters, an 'e' and a combining accent. It is unlikely to be correct to insert a space between them. This is unrelated to lower level issues, like some unicode code points taking more than one 16 bit unichar to represe

Re: Adding spaces to an NSString

2008-03-19 Thread Gerriet M. Denkmann
On 19 Mar 2008, at 04:55, [EMAIL PROTECTED] wrote: Yes, I have, Are you thinking insertString:atIndex:? So at a basic level, can I get the string length, for loop through each character and after each use insertString to add a space? No. You may remember that if NSString talks of "charact

Re: Adding spaces to an NSString

2008-03-18 Thread Jens Alfke
On 18 Mar '08, at 5:51 PM, J. Todd Slack wrote: I am just looking for the most efficient way Some principles: * Insertion into the middle of a string (or array) is inefficient. It's faster to append. * Creating new strings is inefficient (as with - stringByAppendingString:). * printf-like

Re: Adding spaces to an NSString

2008-03-18 Thread Shawn Erickson
On Tue, Mar 18, 2008 at 5:40 PM, J. Todd Slack <[EMAIL PROTECTED]> wrote: > Hello All, > > I am a little stumped today, not sure why, but how would I add a space after > every character in an NSString and produce a new NSString from it. > > So I have something like: (ignore the quotes, I just di

Re: Adding spaces to an NSString

2008-03-18 Thread stephen joseph butler
On Tue, Mar 18, 2008 at 11:10 PM, stephen joseph butler < [EMAIL PROTECTED]> 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 ",

Re: Adding spaces to an NSString

2008-03-18 Thread stephen joseph butler
On Tue, Mar 18, 2008 at 7:40 PM, J. Todd Slack < [EMAIL PROTECTED]> wrote: > Hello All, > > I am a little stumped today, not sure why, but how would I add a space > after > every character in an NSString and produce a new NSString from it. > > So I have something like: (ignore the quotes, I just d

Re: Adding spaces to an NSString

2008-03-18 Thread Matt Long
You could get a char array from your initial NSString and then use stringByAppendingFormat:@"%c " on an NSString in a loop. Notice the space after the %c. -Matt J. Todd Slack wrote: Hi John, Yes, I have, Are you thinking insertString:atIndex:? So at a basic level, can I get the string

Re: Adding spaces to an NSString

2008-03-18 Thread John Stiles
Unless you are doing this hundreds of thousands of times in a row, I doubt you will need to worry about efficiency. By the way, now that I'm thinking about this a little more, you might also consider making an NSAttributedString and setting the kern value for the string to be a large value (e

Re: Adding spaces to an NSString

2008-03-18 Thread J. Todd Slack
Hi John, Yes, I have, Are you thinking insertString:atIndex:? So at a basic level, can I get the string length, for loop through each character and after each use insertString to add a space? I am just looking for the most efficient way, sometimes I suffer from doing things multiple ways, trying

Re: Adding spaces to an NSString

2008-03-18 Thread John Stiles
Have you looked at NSMutableString? The APIs are pretty basic here. I'd recommend working from right-to-left; you'll find it probably makes the logic simpler. J. Todd Slack wrote: Hello All, I am a little stumped today, not sure why, but how would I add a space after every character in an NSS

Adding spaces to an NSString

2008-03-18 Thread J. Todd Slack
Hello All, I am a little stumped today, not sure why, but how would I add a space after every character in an NSString and produce a new NSString from it. So I have something like: (ignore the quotes, I just did it for containment sake..) ³/Users/slack/Music² And I want it to be: ³/ U s e r s