Re: quick newbie NSString question
Re: quick newbie NSString question
- Subject: Re: quick newbie NSString question
- From: Clifford Crawford <email@hidden>
- Date: Sun, 24 Jun 2001 07:59:35 -0400
On Sunday, June 24, 2001, at 04:25 AM, Aaron Tuller wrote:
ok, I have a NSString, it is "1234" (without the quotes).
I want to make it "3412" (without the quotes).
what's the best cocoa way to do this? I've only been able to do it by
turning it into a C string and then going back to a NSString but that
seems silly. and I was thinking of using characterAtIndex: but the whole
Unicode thing scared me off. what kid of data type do I hold the things
that characterAtIndex: returns and how can I put them back into a
NSString. thanks for any help and sorry if this question is really
obvious.
You could do the following:
NSString *newStr, *oldStr = @"1234";
int midpoint = [oldStr length] / 2;
newStr = [[oldStr substringFromIndex:midpoint] stringByAppendingString:
[oldStr substringToIndex:midpoint]];
In other words, find the midpoint of the string, then create a new string
by appending the second half of the old string (everything from the
midpoint to the end) to the first half.
--
Cliff Crawford
http://www.sowrong.org/
"Cliff, you're a god. I want to bear your child." --Ed