swift - '子字符串(到 : )' is deprecated: Please use String slicing subscript with a ' partial range upto' operator

标签 swift substring swift4

如何将以下代码更新到新版本的 swift:

self.areaCodeLael.text! = localNumber.substring(to: localNumber.index(localNumber.startIndex, offsetBy: 3))

我试过关注这篇文章,但我做对了 How can I use String slicing subscripts in Swift 4?

我将我的原始代码调整为 localNumber[..<3]但我得到:

Cannot subscript a value of type 'String' with an index of type 'PartialRangeUpTo'

最佳答案

在这种情况下,我会说 localNumber.prefix(3)。简短而甜美。

关于swift - '子字符串(到 : )' is deprecated: Please use String slicing subscript with a ' partial range upto' operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45922857/

相关文章:

ios - 在快速编程语言中隐藏文本字段的键盘

swift - 我可以在 Swift 中将元类对象转换为协议(protocol)类型吗?

ios - 如何在 swift 4 中对字典数组进行排序

ios - 类型 'ImageSlideshow?' 的值没有成员 'pageControlBottomPadding'

C# 烦恼 - 访问 sting 之外的数据

swift - 使用 TabBarController 传递数据

ios - 使用 SwiftyJSON 的 NSDictionary 到 json 字符串到 json 对象

ios - 在 Swift 中解码 JSON Web token

string - 拆分字符串并将子字符串转换为 Go 中的整数

Java:从特定字符后开始的字符串中获取子字符串