Re: Chopping off the end of a string with - (void)deleteCharactersInRange:(NSRange)aRange
Re: Chopping off the end of a string with - (void)deleteCharactersInRange:(NSRange)aRange
- Subject: Re: Chopping off the end of a string with - (void)deleteCharactersInRange:(NSRange)aRange
- From: "John C. Randolph" <email@hidden>
- Date: Mon, 3 Mar 2003 15:01:27 -0800
On Monday, March 3, 2003, at 02:03 PM, Mark Ogilvie wrote:
I've been working my way through some NSString programs to get the hang
of them and I wanted to remove a set number of letters (doesn't matter
what the letters are) from the end of a string. I spotted the
deleteCharactersInRange method and thought to just use a for-loop to go
back from the end of the string, but it calls for an NSRange object and
there is no NSRange listed in help. The only thing listed is
NSRangeSpecifier. Nor did I find much on an archive search. I know
that a NSRange object is a struct with two integers, start and length,
but I can't find anything on how you can create one from a string. Or
is there a more obvious way of shrinking a string?
I'm not clear on what you're asking for. NSRange is just a location
and a length, and you create it with NSMakeRange(). It sounds like
what you want is actually a substring, and you can get that with
NSString's -substringWithRange:, -subStringFromIndex: or
-substringToIndex: methods.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.