trouble getting c-chars from NSString
trouble getting c-chars from NSString
- Subject: trouble getting c-chars from NSString
- From: Daniel Child <email@hidden>
- Date: Thu, 31 Mar 2005 11:12:55 -1000
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.
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]);
On Thursday, March 31, 2005, at 05:59 AM, email@hidden wrote:
At 16:48 Uhr -1000 30.03.2005, Daniel Child wrote:
Sorry, I am a newbie and I only did a tiny bit of C, so this
question is pretty basic. I am trying to convert an NSString to a
C-String so that I can remove certain characters. Somehow I don't
seem to be able to get the cString returned from the [NSString
cString] method to be assigned to a character array.
You're aware that you don't need to use a C string, right? You can
just use an NSMutableString and characterAtIndex: to do the work.
That will also take care of international characters that might not
fit in a C string, which you'd otherwise lose.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
_______________________________________________
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