LoginSignup
16
13

More than 5 years have passed since last update.

[Swift]文字列検索で範囲と位置の取得

Last updated at Posted at 2014-07-28

指定した文字列の検索は以下の通りです。

コード

//文字列の範囲を取得
var str: NSString = "abcdefghi"
var range: NSRange = str.rangeOfString("cde")
println(range)

//文字列の位置を取得
var loc = str.rangeOfString("cde").location
println(loc)

出力結果

(2,3)
2

16
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
13