How can we subtract multiple ranges of type Range<String.Index> from one range of type Range<String.Index>?
Example:
let str = "let <#name#> = <#value#>"
let range = str.startIndex..<str.endIndex
//the range of str is {0, 24}
//the range of <#name#> is {4, 8}
//the range of <#value#> is {15, 9}
How can we subtract the ranges {4, 8} and {15, 9} from the range of str to obtain the ranges of "let " and " = "
Here's an extension to
StringProtocolthat will return an array of ranges from a string that are outside the passed in ranges:Here's some sample code to demonstrate its use:
Output:
["let ", " = "]