Swift replace substring regex

前端 未结 6 1530
执念已碎
执念已碎 2020-11-29 04:53

I am attempting to use regular expression to replace all occurrences of UK car registrations within a string.

The following swift code works perfectly for a when the

6条回答
  •  旧时难觅i
    2020-11-29 05:56

    Warning

    Do not use NSRange(location: 0, length: myString.count) as all examples above quoted.

    Use NSRange(myString.startIndex..., in: myString) instead!

    .count will count newline characters like \r\n as one character - this may result in a shortened, thus invalid, NSRange that does not match the whole string.

    (.length should work)

提交回复
热议问题