• 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: Julien Palmas <email@hidden>
  • Date: Thu, 31 Mar 2005 12:11:26 +0900

if you want to get a cString from a NSString and do something with it after, you should use

NSString *test = @"a string";
char *aChar;


aChar = (char *)malloc(sizeof([test cString]+1));
[test getCString:aChar];


On Mar 31, 2005, at 11:49 AM, Daniel Child wrote:

Hi All,

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.

Here's what I have at this point.

NSString *original = @<some string of characters that contains digits> e.g. asd5sd
char *origChars = [original cString]; // my c-string

*charPtr;
char charArray[];
char newWord[]; // a word without numbers
int numCharsInNewWord

If I try to assign origChars to either *charPtr or charArray, I get an error. What I'm hoping to do is to get a word that is devoid of numbers.

numCharsInNewWord = 0;
while (charPtr != '\0') {
if (charPtr >= '\0' && charPtr <= '\9')
; // don't copy digits
else
newWord[numCharsInNewWord++];
charPtr++;
}

Thanks in advance!

Daniel


_______________________________________________
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
 _______________________________________________
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: NSTableView and row selection
  • Next by Date: Re: adding NSView from other application
  • Previous by thread: trouble getting c-chars from NSString
  • Next by thread: trouble getting c-chars from NSString
  • Index(es):
    • Date
    • Thread