Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting NSString into const char

I have an String and i want to convert it into Const Char . I Had tried but it's not Working

NSString *str4 = [NSString stringWithUTF8String:character];
like image 240
Aadil Avatar asked Jun 21 '11 13:06

Aadil


3 Answers

Do like this:

NSString *strSQL = [[NSString alloc]init];

then something in your *strSQL

then this statement:

const char *bar = [strSQL UTF8String]; 
like image 120
Vipin Avatar answered Oct 18 '22 00:10

Vipin


NSString *myString = @"Hello";  

const char *cString = [myString cStringUsingEncoding:NSASCIIStringEncoding];

or

const char * cstr2 = [ myString UTF8String ];
like image 45
Rams Avatar answered Oct 18 '22 00:10

Rams


You should use cStringUsingEncoding: method
Take a look at this method here

like image 1
gsempe Avatar answered Oct 18 '22 00:10

gsempe