LoginSignup
3
2

More than 5 years have passed since last update.

swift 指定の文字列の位置を最後から検索

Posted at

最後から検索する場合は、
rangeOfStringのoptions:NSStringCompareOptions.BackwardsSearchを指定する。

swift
var hogeNsStr:NSString = "yoshiganbaruzou yoshiyoshi"
var pos = hogeNsStr.rangeOfString("yoshi", options:NSStringCompareOptions.BackwardsSearch).location
println("pos \(pos)")

String型ではなく、NSString型でないとlocationはとれなかった。

あと、検索にひっかからない場合には下記ような値が入るので注意!

pos 9223372036854775807
3
2
2

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
3
2