我的代码中有一个错误,例如“无法将'NSRange'类型的值(aka'_NSRange')转换为预期的参数类型'Range'(aka'范围')”,但是我不知道如何解决这个问题帮我?
我在这里发布我的代码。
NSUserDefaults.standardUserDefaults().setObject("Hey I have started using this Chat App", forKey: "Status")
var strNumber: String = txtPhoneNumber.text!
var myRange: NSRange = NSMakeRange(0, 2)
var myRange1: NSRange = NSMakeRange(0, 1)
var ran: String = strNumber.substringWithRange(myRange) ------> //This line error shows.
var ran1: String = strNumber.substringWithRange(myRange1)
if (ran == "00") || (ran == "60") || (ran == "62") || (ran == "65") || (ran == "91") || (ran == "44") {
strNumber = strNumber.stringByReplacingOccurrencesOfString(ran, withString: "") as String
}
else if (ran1 == "0") {
strNumber = strNumber.stringByReplacingOccurrencesOfString(ran1, withString: myRange1) as NSString
//str_number = str_number.stringByReplacingOccurrencesOfString(ran1, withString: "", options: NSCaseInsensitiveSearch, range: myRange1)
}
最佳答案
您应该将strNumber
转换为NSString:var strNumber: NSString = txtPhoneNumber.text!
更多内容:NSRange to Range<String.Index>