[swift-users] Was the String contains(_:) method changed in Swift 4?

Martin R martinr448 at gmail.com
Wed Nov 8 03:28:19 CST 2017


Unicode correct string comparison _is_ tricky, but `s.contains(s)` will always be true :)

And `s.contains(ss)` with your example strings return false.

Regards, Martin

> Am 08.11.2017 um 09:56 schrieb Quinn The Eskimo! via swift-users <swift-users at swift.org>:
> 
> 
> On 8 Nov 2017, at 08:47, Martin R via swift-users <swift-users at swift.org> wrote:
> 
>> but apparently only if Foundation is imported.
> 
> Which isn’t a huge surprise when you consider how tricky string containment is.
> 
> import Foundation
> 
> // U+00DF LATIN SMALL LETTER SHARP S
> 
> let s = "Friedrichstra\u{df}e"
> let ss = "strasse"
> if s.contains(s) {
>    print("It's a street!")
> }
> 
> Share and Enjoy
> --
> Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list