user3647675 user3647675 - 1 year ago 110
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?

Answer Source

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 $."

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download