Re: Clever way to replace in a NSString
Re: Clever way to replace in a NSString
- Subject: Re: Clever way to replace in a NSString
- From: Allan Odgaard <email@hidden>
- Date: Mon, 29 Mar 2004 21:16:11 +0200
On 29. Mar 2004, at 15:30, Mathieu Godart wrote:
I'm wondering if there is an easy and efficient way to replace a
specific
character by an other in a NSString (let's say I want to replace all
spaces
by '+' char).
This has already been answered, but since it is some time since I last
made a push for ObjectiveC++ and CocoaSTL
<
http://www.top-house.dk/~aae0030/cocoastl/> then let me show you how
to do it using that:
NSString* src = @"Hello world, this is nice";
NSMutableString* dst = [NSMutableString string];
std::replace_copy(beginof(src), endof(src), back_inserter(dst), ' ',
'+');
The second funny thing I want to do with NSString is to relace all
characters with accents ('i', 'h', 'o', 'g', etc.) by their equivalent
without accent ('e, 'e', 'i', 'c', etc.). OK, I could do that manualy,
but
those functions exist in PHP, for instance, and I cannot belive that
Cocoa
doesn't have high level functions (or methods) to do that directly.
Well, Cocoa is a GUI/application framework for an OS which is unicode
compliant and which strength has long been typography -- PHP OTOH is
for web-publishing where the lowest common denominator is often the
target, hence the difference in priorities.
At present I think Cocoa only allows you to identify these accented
characters using the decomposableCharacterSet.
** Cocoa FAQ: <
http://www.alastairs-place.net/cocoa/faq.txt> **
_______________________________________________
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.