Re: Temporary Strings
Re: Temporary Strings
- Subject: Re: Temporary Strings
- From: Tony Cate <email@hidden>
- Date: Wed, 24 Aug 2005 16:23:00 -0500
How about making lookingFor a mutable string? Then the line:
NSString *lookingFor = [[NSString alloc]initWithFormat:@"{%d",ch];
becomes,
[lookingFor setString:[NSString stringWithFormat:@"{%d",ch]];
Tony
3 Cats And A Mac
http://www.3caam.com
On Aug 24, 2005, at 11:25 AM, Paul Harvey wrote:
I have a loop that uses NSRanges to look in a large string for
certain occurences of characters and keeps a count of how many are
found.
I'm looking for {1, {2, {3, {4.... and so on. I use a loop for the
integer and create an NSString in side the loop
My question:
is it necessary to create a new NSString for each one? It seems
wasteful to me. What I would like to do is simply pass "{" and
concatenate the integer value to it. Is this possible?
My code:
// count the chapters. Search for {x where x is the chapter
// number. Keep going until false. That's the last chapter
number
int ch = 0;
int bl = [bookText length];
BOOL found = YES;
NSRange searchRange,foundRange;
foundRange.location=0;
foundRange.length=0;
while(found == YES) {
ch++;
NSString *lookingFor = [[NSString alloc]
initWithFormat:@"{%d",ch];
searchRange.location = foundRange.location;
searchRange.length = bl-foundRange.location;
foundRange = [bookText rangeOfString:lookingFor
options:NSCaseInsensitiveSearch
range:searchRange];
if(foundRange.length == 0) {
found = NO;
}
[lookingFor release];
}
ch--; // The loop presents one more chapter count than
there actually is
I create a new lookingFor NSString each time through the loop, then
throw it away when I'm done.
--
Paul Harvey
Lead Programmer
email@hidden
Hiddenfield Software
"Creating useful software for Mac OS X"
www.hiddenfield.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden