Re: I don't get how to cast an integer to string
Re: I don't get how to cast an integer to string
- Subject: Re: I don't get how to cast an integer to string
- From: Charles Bennett <email@hidden>
- Date: Wed, 22 May 2002 08:45:43 -0400
Ted Petrosky wrote:
I am new at this so please...
i have a mutable string and I want to insertstring atindex however i need to
insert an integer. like in a c sting ("this is an integer %i.", integer).
how can I cast the integer to string:
int j=65;
NSMutableString *aFormattedString = [[NSMutableString alloc]
initWithFormat:@"There are rows"];
[aFormattedString insertString:[j stringValue] atIndex:10];
Well, since j is a plain ol' c type integer it doesn't respond to objective c messages
[j stringValue] is meaningless..
You want to do something like this.
[aFormattedString insertString:[NSString stringWithFormat:@"%i",j] atIndex:10];
Of course you could do that from the very start, without a mutable string
NSString *aFormattedString = [[NSString alloc] initWithFormat:@"There are %i rows",j];
or if you are just doing a diagnostic print..
NSLog(@"There are %i rows",j);
Since you are doing an alloc.. init.. remember that it is your job to release
the string when you are done, or you will leak memory.
You might want to pick up a book like Hillegass "Cocoa Programming for Mac OS X"
or something along that line...
Chuck
I am just learning how to RTM.
Thanks,
Ted
_______________________________________________
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.
--
UPS Management software for OS X
http://www.powerguardian.com
_______________________________________________
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.