Swift下的字串尋找

來源:互聯網
上載者:User

標籤:ios   swift   字串   

var test="11111111111test"

if (string.rangeOfString("test") != nil) //注意!=左右的空格

{

  println("find")

}


如果想獲得位置,就:

var t=string.rangeOfString("test")

開始位置

t?.startIndex

結束位置

t?.endIndex


另,再補充個方法,google的

let string = "hello Swift";let subString = (string as NSString).containsString("Swift")if(subString){println("Exist")}


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

Swift下的字串尋找

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.