Re: Changing Case
Re: Changing Case
- Subject: Re: Changing Case
- From: Alastair Houghton <email@hidden>
- Date: Thu, 18 Mar 2004 14:40:10 +0000
On 18 Mar 2004, at 13:48, Mathew Peterson wrote:
>
Is there any neat Cocoa way of changing the case of a single character
>
or string? I am just looking around in the NSText world for the first
>
time and I am probably missing something rather simple.
What's wrong with doing e.g.
NSMutableString *myString = [NSMutableString
stringWithUTF8String:"hello"];
NSRange rangeOfCharacter = NSMakeRange(0,1);
[myString
replaceCharactersInRange:rangeOfCharacter
withString:[[myString substringWithRange:rangeOfCharacter]
uppercaseString]];
I suppose you might argue that this kind of thing is overkill when you
just want to change a single character, *but* unlike most methods that
deal with individual characters, it'll still work for strings
containing unusual or even composed characters, even where the length
of the uppercase version differs from the original version. (That is,
provided you use an appropriate range.)
If you use code like that a lot, it might be worth wrapping it up in a
method and putting the method in a category on NSMutableString.
Kind regards,
Alastair.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.
References: | |
| >Changing Case (From: Mathew Peterson <email@hidden>) |