开发者

convert string to char

I have on one string like @"K_h_10_K_d_10_K_c_13_T_c_13_T_s_13"

I 开发者_JS百科separate them by @"_" using appCardString=[substringAppCard componentsSeparatedByString:@"_"];

then I have to convert them in to char and want to put in char[] ....

how can I do that ..

please help me ....

It's crashing here

appusedFaces[i]=[[NSString stringWithFormat:@"%@",[appCardString objectAtIndex:i]] charValue];


This will work:

appusedFaces[i]=[[appCardString objectAtIndex:i] characterAtIndex:0];

Though you should add a check that the string has at least one character. You should also be aware that char can only hold character codes up to 255 (unichar can handle any Unicode character).

It also looks like you have some numeric codes in your test string. Checking if the string has more than one character and then calling [[appCardString objectAtIndex:i] intValue] for those characters will handle these.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜