Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString get -characters

I want to get the characters of an NSString. Like this:

NSString *data;
const char * typein = [[data characters] UTF8String];

But obviously NSString won't respond to -characters. How do I get the characters of NSString?

thanks, Elijah

like image 405
objectiveccoder001 Avatar asked Oct 08 '10 00:10

objectiveccoder001


1 Answers

You can use this function:

for(int i =0 ;i<[myString length]; i++) {
  char character = [myString characterAtIndex:i];
}

or

NSString *str = @"astring";
const char *cString = [str UTF8String];
like image 120
mklfarha Avatar answered Oct 01 '22 18:10

mklfarha