Re: trouble getting c-chars from NSString
Re: trouble getting c-chars from NSString
- Subject: Re: trouble getting c-chars from NSString
- From: "M. Uli Kusterer" <email@hidden>
- Date: Thu, 31 Mar 2005 23:47:51 +0200
At 11:12 Uhr -1000 31.03.2005, Daniel Child wrote:
Actually, your suggestion is precisely what I ended up using.
However, I did have to use a C-String to paste the characters
together because I did not find a method that does
"stringFromChars." Here was my approach.
stringWithCharacters:length: sounds like what you want.
NSString *original = [NSString stringWithString:@"[asdf123asdf]"];
NSCharacterSet *nums = [NSCharacterSet
characterSetWithCharactersInString:@" 0123456789[]"];
NSString *numFree;
int i; unichar c; int numNewChars = 0;
char noNums[100];
for (i = 0; i < [original length]; i++)
{
c = [original characterAtIndex: i];
if (!([nums characterIsMember: c]))
{
noNums[numNewChars++] = c; // IS THERE A FOUNDATION METHOD
THAT WORKS HERE?
}
}
numFree = [NSString stringWithCString: noNums];
numFree = [numFree substringToIndex: numNewChars];
printf("%s", [numFree cString]);
There's a much easier way for doing this: Get the -invertedSet from
nums and then use -stringByTrimmingCharactersInSet: on your string
instead.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden