Find substring, Swift code to check subString in a string.

February 21, 2015   ·   0 Comments

var string = "hello Swift"

if string.rangeOfString("Swift") != nil{
    println("exists")
}

// alternative: not case sensitive
if string.lowercaseString.rangeOfString("swift") != nil {
    println("exists")
}

  
        let string2 = "Hello.World"
        let needle: Character = "."
        if let idx = find(string2, needle) {
            let pos = distance(string2.startIndex, idx)
            println("Found \(needle) at position \(pos)")
        }
        else {
            println("Not found")
        }
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Swift491

Swift

Amazon

adsbygoogle

Recent Posts

Categories

Amazon