2017-12-07 6 views
1

私は2/42という文字列を持っています。ここで2 & 42は動的です。今は/42を文字列の上付き文字として設定します。私は/42の範囲を見つけることができません。私はどのように迅速に範囲を見つけるのですか教えてください?属性付き文字列の文字列の範囲を取得するには?

+0

'NSRegularExpression'、' NSScanner'、 'rangeOf'('/'が見つかった場合)は明らかに十分です... – Larme

答えて

1

属性文字列の変更可能な文字列には、特定の文字列の範囲を見つける機能があります。

(スイフト4)を試して、参照:

let stringValue = "2/42" 
let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: stringValue) 
let range: NSRange = attributedString.mutableString.range(of: "/42", options: .caseInsensitive) 
print("range - \(range)") 

結果:
範囲 - {1、3}

文献スナップ:

enter image description here

関連する問題