home.social

#nsstring — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #nsstring, aggregated by home.social.

  1. Matching prefixes in Swift strings

    How do you determine if one string starts with another, in Swift?

    Surely that's exactly what the hasPrefix(_:) method is for:

    let greeting = "Hello"

    let sentence = "hello, this is dog."

    if sentence.hasPrefix(greeting) {

    print("Hi! Nice to meet you!")

    } else {

    print("No can haz etiquette?")

    }

    No can haz etiquette?

    Wot?

    The problem is that hasPrefix is not meant for general use with human text; it's barely better than a byte-wise comparison. It only guarantees that it [...]

    wadetregaskis.com/matching-pre

  2. Matching prefixes in Swift strings

    How do you determine if one string starts with another, in Swift?

    Surely that's exactly what the hasPrefix(_:) method is for:

    let greeting = "Hello"

    let sentence = "hello, this is dog."

    if sentence.hasPrefix(greeting) {

    print("Hi! Nice to meet you!")

    } else {

    print("No can haz etiquette?")

    }

    No can haz etiquette?

    Wot?

    The problem is that hasPrefix is not meant for general use with human text; it's barely better than a byte-wise comparison. It only guarantees that it [...]

    wadetregaskis.com/matching-pre

  3. Matching prefixes in Swift strings

    How do you determine if one string starts with another, in Swift?

    Surely that's exactly what the hasPrefix(_:) method is for:

    let greeting = "Hello"

    let sentence = "hello, this is dog."

    if sentence.hasPrefix(greeting) {

    print("Hi! Nice to meet you!")

    } else {

    print("No can haz etiquette?")

    }

    No can haz etiquette?

    Wot?

    The problem is that hasPrefix is not meant for general use with human text; it's barely better than a byte-wise comparison. It only guarantees that it [...]

    wadetregaskis.com/matching-pre