Re: NSString comparing alphanumerically (with numbers)
Re: NSString comparing alphanumerically (with numbers)
- Subject: Re: NSString comparing alphanumerically (with numbers)
- From: zauhar <email@hidden>
- Date: Wed, 22 May 2002 10:24:36 -0400
- Scubber-version: 1.7 (portal)
Hi Nicolas,
I don't know if this is "simple", but in my code I recently needed to
sort an NSMutableArray, which suggests this approach:
You could define a new class (say "MyString") that would include an
NSString as an element, along with a custom method to compare two
MyString objects for lexical priority. You could then sort a mutable
array of MyString instances using the sortUsingSelector method of
NSMutableArray. (You need to pass the selector for your custom sorting
method to sortUsingSelector.)
In the Cocoa doc browser there is also a method called
"localizedCompare" listed for NSString, but no description of what it
does.
Randy
Hi !
(I hope someone will have a hint on this one, unless I'm now banned
completely ;-))
Is there a direct/simple way to compare two NSStrings (during a sort),
while keeping numbers as numbers
mixed with text ? (ie toto1 < toto2 < toto10 and not toto1 < toto10 <
toto2 ) ?
what would be the best *cocoa* way to do it ? (Or should I compare each
character myself?)
(neither caseInsensitiveCompare nor NSLiteralSearch do the job)
thanks ^_^
(et bonjour aux francais, il semble qu'on soit nombreux ici !)
_______________________________________________
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.
Randy J. Zauhar, PhD
Assoc. Prof. of Biochemistry
Director, Graduate Program in Bioinformatics
Dept. of Chemistry & Biochemistry
University of the Sciences in Philadelphia
600 S. 43rd Street
Philadelphia, PA 19104
Phone: (215)596-8691
FAX: (215)596-8543
E-mail: email@hidden
Web:
http://tonga.usip.edu/zauhar
Thought for the ages:
"If you have conceptions of things that you can have no conception of,
then the conception and the thing appear to co-incide." -- C.G. Jung
Thought for the new millennium:
"Nothing is gooder than watching cartoons." -- Catherine Zauhar, age 5
_______________________________________________
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.