Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rbeatajane

macrumors newbie
Original poster
Mar 11, 2011
8
0
Hi,


Code:
char string1[512] = "Hello";
	NSString* string = @"World!";
	NSString* string2 = (NSString*)string1;
	string2 = [string stringByAppendingString:string2];
	NSLog(@"string:%@",string2);

I have to append the strings. One is of c-type and the other is of NSObject type.
How to append these two strings.I tried to append two NSStrings and I got the output.
I'm getting an EXC_BAD_ACCESS when tried to execute the above code.
How to make the char as an NSObject type.
 

rbeatajane

macrumors newbie
Original poster
Mar 11, 2011
8
0
Yes

NSString* string2 = [NSString stringWithUTF8String:string1]; solved my problem
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
How do i convert a NSString to a char*?

Did you look in the documentation? There is a whole group of methods titled "Getting C Strings". In addition the NSString documentation links to the String Programming Guide which I would expect you to have read. It has a section "Creating and Converting String Objects" which demonstrates answers to every question in this thread.

The ability to use the documentation is a core programming skill that I would suggest you need to develop. Simply posting questions on forums before you have read the documentation is very lazy.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.