user3647675 user3647675 - 7 months ago 59
Objective-C Question

How to take NSRange in swift?

I am very much new to swift language. I am performing some business logic which needs to take

from given String.

Here is my requirement,
Given Amount = "144.44"
of only cent part i.e. after "."

Is there any API available for doing this?


You can do a regex-based search to find the range:

let str : NSString = "123.45"
let rng : NSRange = str.range("(?<=[.])\\d*$", options: .RegularExpressionSearch)

Regular expression "(?<=[.])\\d*$" means "zero or more digits following a dot character '.' via look-behind, all the way to the end of the string $."