久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

NSString intValue 不能用于檢索電話號碼

NSString intValue not working for retrieving phone number(NSString intValue 不能用于檢索電話號碼)
本文介紹了NSString intValue 不能用于檢索電話號碼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個電話號碼,格式為易于閱讀的電話號碼,即 (123) 123-4567

I have a phone number formatted as an easy to read phone number, i.e., (123) 123-4567

但是,當我想在代碼中使用該電話號碼時,我需要將該字符串解析為一個數字變量(例如 int)

However, when I want to use that phone number in code, I need to parse that string into a number variable (such as an int)

但是,[string intValue]; 不起作用 - 我在以前的項目中使用了大約一百萬次 intValue,全部沒問題,但是在這里,我傳入的每個字符串,我都會得到相同的隨機 int 退出:

However, [string intValue]; doesn't work - I've used intValue about a million times in previous projects, all with no problem, however here, every string I pass in, I get the same, random int back out:

- (int)processPhoneNumber:(NSString *)phoneNumber {
      NSMutableString *strippedString = [NSMutableString stringWithCapacity:10];

      for (int i=0; i<[phoneNumber length]; i++) {
           if (isdigit([phoneNumber characterAtIndex:i])) {
                  [strippedString appendFormat:@"%c",[phoneNumber characterAtIndex:i]];
           }
      }

     NSLog(@"clean string-- %@", strippedString);

     int phoneNumberInt = [strippedString intValue];

     NSLog(@"**** %d
 &i", phoneNumberInt, phoneNumberInt);

     return phoneNumberInt;
}

那么當我調用這個方法時:

Then when I call this method:

NSLog(@"%i", [self processPhoneNumber:self.phoneNumberTextField.text]);

我得到:2147483647.我給這個方法的每個輸入都會返回:2147483647

I get: 2147483647. Every input I give this method returns: 2147483647

推薦答案

正如 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.

另請參閱表示電話號碼的正確方法是什么?

這篇關于NSString intValue 不能用于檢索電話號碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
UIScrollView scrolling only with one finger(UIScrollView 只能用一根手指滾動)
Using UITouch inside a UIScrollView(在 UIScrollView 中使用 UITouch)
UitextField resignFirstResponder does not work in scroll view(UitextField resignFirstResponder 在滾動視圖中不起作用)
How to Stop a UIScrollView from Swallowing Touches(如何阻止 UIScrollView 吞下觸摸)
Make background color change during scroll(在滾動期間更改背景顏色)
主站蜘蛛池模板: 国产区在线看 | 精品在线一区 | 亚洲欧美在线观看 | 欧美黄视频 | 亚洲精品日韩一区二区电影 | 国产精品s色| 久久国产一区二区三区 | 久草新在线| 伦理午夜电影免费观看 | www.色综合 | 国产网站在线播放 | 最新中文字幕在线 | 久久成人精品 | 亚洲毛片在线观看 | 草久视频 | 激情久久网 | 国产色婷婷精品综合在线手机播放 | 午夜天堂精品久久久久 | 国产在线精品一区二区三区 | 一级黄色毛片免费 | 久久久影院| 天天久久| 亚洲欧美一区二区三区在线 | 一区二区三区精品视频 | 国产成人jvid在线播放 | 久久精品91| 亚洲精品国产一区 | 俺去俺来也www色官网cms | 深夜福利影院 | 日日夜夜精品 | 韩国av影院 | 国产乱码一区 | 亚洲毛片 | 中文字幕亚洲视频 | 蜜桃官网 | 一区欧美 | 精品欧美乱码久久久久久1区2区 | 精品视频一区二区三区在线观看 | 欧美视频1区| 亚洲欧美在线观看 | 久久区二区 |