• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: trouble getting c-chars from NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >trouble getting c-chars from NSString (From: Daniel Child <email@hidden>)

  • Prev by Date: Re: trouble getting c-chars from NSString
  • Next by Date: Re: NSImageView.
  • Previous by thread: Re: trouble getting c-chars from NSString
  • Next by thread: NSTimer not firing if date changed in Sys Prefs
  • Index(es):
    • Date
    • Thread