黑马程序员技术交流社区
标题: 字符串转化成其它类型注意事项 [打印本页]
作者: shenlongzs 时间: 2014-4-7 21:51
标题: 字符串转化成其它类型注意事项
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)
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |