ios - Assigning charAtIndex to stringWithCharacters gives invalid cast warning and bad access error -


i'm trying grab firstname , lastname firstname+lastname.

int loop=0; nsmutablestring *firstname = [[nsmutablestring alloc]init];  nsmutablestring *fullname = [[nsmutablestring alloc]initwithstring:@"anahita+havewala"];  (loop = 0; ([fullname characteratindex:loop]!='+'); loop++) {     [firstname appendstring:[nsstring stringwithcharacters:(const unichar *)[fullname characteratindex:loop] length:1]]; } nslog(@"%@",firstname); 

i tried typecasting unichar const unichar* because characteratindex returns unichar stringwithcharacters accepts const unichar.

this causes cast smaller integer type warning , app crashes (bad access) when line encountered.

why string operations complicated in objective c?

try out:

nsmutablestring *firstname = [[nsmutablestring alloc] init];     nsmutablestring *fullname = [[nsmutablestring alloc] initwithstring:@"anahita+havewala"];  (nsuinteger loop = 0; ([fullname characteratindex:loop]!='+'); loop++) {     unichar mychar = [fullname characteratindex:loop];     [firstname appendstring:[nsstring stringwithformat:@"%c", mychar]]; }  nslog(@"%@", firstname); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -