1、字符串转化为int、float型
字符串 str
int j = [str intValue];
float j = [str floatValue];
注意:如果字符串由数字开头,转化为起始的数字,否则转化为0,一定确保开头是数字。 2、转化BOOL型
BOOL型,查文档得知,如果转化为BOOL型,Returns YES on encountering one of "Y", "y", "T", "t", or a digit 1-9—the method ignores any trailing characters. Returns NO if the receiver doesn’t begin with a valid decimal text representation of a number.(由Y,y,T,t,1-9开始的字符串转化为YES,其余的为NO)
|