<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">I think this is important enough and useful for we to be in the core standard library</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-size: 13.6px; line-height: 1.45; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; overflow: auto; margin-top: 0px; margin-bottom: 0px; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51); orphans: 2; widows: 2;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">extension</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span></span> {

    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">index</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">of</span> <span class="pl-smi" style="box-sizing: border-box;">string</span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-smi" style="box-sizing: border-box; color: rgb(51, 51, 51);">options</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.CompareOptions <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> .<span class="pl-smi" style="box-sizing: border-box;">literal</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-&gt;</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">?</span> {
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">of</span>: string, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">options</span>: options)<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">?</span>.<span class="pl-smi" style="box-sizing: border-box;">lowerBound</span>
    }

    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">indexes</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">of</span> <span class="pl-smi" style="box-sizing: border-box;">string</span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-smi" style="box-sizing: border-box; color: rgb(51, 51, 51);">options</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.CompareOptions <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> .<span class="pl-smi" style="box-sizing: border-box;">literal</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-&gt;</span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span>] {
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> result<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span>] <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> []
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> start <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> startIndex
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">while</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> range <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">of</span>: string, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">options</span>: options, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>: start<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">..&lt;</span>endIndex) {
            result.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">append</span>(range.<span class="pl-smi" style="box-sizing: border-box;">lowerBound</span>)
            start <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> range.<span class="pl-smi" style="box-sizing: border-box;">upperBound</span>
        }
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> result
    }

    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">ranges</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">of</span> <span class="pl-smi" style="box-sizing: border-box;">string</span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-smi" style="box-sizing: border-box; color: rgb(51, 51, 51);">options</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.CompareOptions <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> .<span class="pl-smi" style="box-sizing: border-box;">literal</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-&gt;</span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Range</span>&lt;<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span>&gt;] {
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> result<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Range</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&lt;</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Index</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&gt;</span>] <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> []
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> start <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> startIndex
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">while</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> range <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">of</span>: string, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">options</span>: options, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">range</span>: start<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">..&lt;</span>endIndex) {
            result.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">append</span>(range)
            start <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> range.<span class="pl-smi" style="box-sizing: border-box;">upperBound</span>
        }
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> result
    }

}</pre><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">Source is not mine, I’ve found here: <a href="http://stackoverflow.com/a/32306142/4550651" class="">http://stackoverflow.com/a/32306142/4550651</a></div><div class=""><br class=""></div><div class="">Best and happy 2017</div><div class=""><br class=""></div><div class="">Carlos García</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>