Swift 3: String search backwards -


i want search backwards in string. examples found not running on current swift 3.0. ".backwardssearch" not option available on xcode 8. idea, how can done? example:

let rpos = rindex(sourcestring, searchstring) 

or

let rpos = sourcestring.rindex(of: searchstring) 

xcode autocomplete suggest this:

let rpos = sourcestring.range(of:searchstring, options:string.compareoptions.backwards, range:nil, locale:nil) 

however, range , locale have defaults of nil, can omit them:

let rpos = sourcestring.range(of:searchstring, options:string.compareoptions.backwards) 

and options of type string.compareoptions need last part:

let rpos = sourcestring.range(of:searchstring, options:.backwards) 

(thanks @martinr pointing out shortened versions)


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -