(Swift) Function to parse string (from-to)

前端 未结 1 496
半阙折子戏
半阙折子戏 2021-01-28 21:56

Is any other ways to parse string \"from-to\"? I mean when there is a value we need and we know about string before and after it. I`ve just created such functi

1条回答
  •  臣服心动
    2021-01-28 22:27

    You could do something like this using substringWithRange:

    func substringBetween(start: String, and end: String) -> String? {
        if let startIndex = rangeOfString(start, options: .LiteralSearch, range: nil, locale: nil)?.endIndex,
               endIndex = rangeOfString(end, options: .LiteralSearch, range: startIndex..

    0 讨论(0)
提交回复
热议问题