【发布时间】:2018-04-23 09:52:32
【问题描述】:
我有一个字符串[Desired Annual Income] /([Income per loan %] /100)
使用这个字符串,我必须在 Swift3 中找到两个子字符串“期望的年收入”和“每笔贷款的收入百分比”。
我正在使用下面的代码来实现这个'How do I get the substring between braces?':
let myString = "[Desired Annual Income] /([Income per loan %] /100)"
let start: NSRange = (myString as NSString).range(of: "[")
let end: NSRange = (myString as NSString).range(of: "]")
if start.location != NSNotFound && end.location != NSNotFound && end.location > start.location {
let result: String = (myString as NSString).substring(with: NSRange(location: start.location + 1, length: end.location - (start.location + 1)))
print(result)
}
但作为输出,我只得到“期望的年收入”,我怎样才能得到所有子字符串?
【问题讨论】:
-
你期望的 OP 是什么
-
输出应该是期望的年收入和每笔贷款的收入百分比。
标签: ios string swift3 substring