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: "M. Uli Kusterer" <email@hidden>
- Date: Mon, 29 Mar 2004 19:21:33 +0100
Mathieu,
first things first: You can't change an NSString. Make a mutableCopy
of it, which gives you an NSMutableString. You can change that to
your heart's content.
At 15:30 Uhr +0200 29.03.2004, Mathieu Godart wrote:
I'm more a C programer than Cocoa developper (for the moment ;-) ), for that
reason, the best way I can see is converting the string in C and manipulate
it with my good old C functions.
That would actually be bad, because you'd screw up all higher-number
Unicode characters, like Umlauts etc. Instead, use characterAtIndex:
and then switch on that.
But I think Cocoa might have some functions
(or methods) that directly replace charaters in a string.
I actually think there is some "replace" function somewhere in
there. Have a look at the NSString docs. If I'm misremembering here
(it may be new in 10.2 or something like that...), try rangeOfString:
and the other manipulation functions NSMutableString offers.
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.
I don't think that's built into Cocoa. If Apple offers something
like that, it's probably in some WebObjects framework ("sold
separately").
One laste thing, is it possible to extract a substring matching a reg exp?
There are a couple of Regexp frameworks that let you do that. Check
out the Cocoadev.com Wiki, they have a list of add-on classes and
frameworks, and there are several Regexp classes in there. You might
also have a look at NSScanner. It doesn't do Regular Expressions, but
it is a faster alternative if you're just doing simple things like
trying to get a list of numbers out of a string or something like
that.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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.