且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NSString intValue 不能用于检索电话号码

更新时间:2022-05-26 23:05:21

正如 CRD 已经解释的那样,您正在尝试将该字符串转换为太小而无法容纳该值的类型,并且您正在取回最大值该类型的可能值.

As CRD has already explained, you're trying to convert that string to a type that's too small to hold the value, and you're getting back the maximum possible value for that type.

然而,你真正的问题是更深层次的.电话号码"并不是真正的号码.它不代表数量.你永远不会对一个进行算术运算.它实际上是一串数字,你应该这样处理它.不要转换它;只对字符串进行操作.

Your real problem is deeper, however. A phone "number" isn't really a number. It doesn't represent a quantity. You would never perform arithmetic on one. It's actually a string of digits, and you should handle it that way. Don't convert it; just operate on the string.

另请参阅表示电话号码的正确方法是什么?