#nsstring — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #nsstring, aggregated by home.social.
-
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 [...]
https://wadetregaskis.com/matching-prefixes-in-swift-strings/
-
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 [...]
https://wadetregaskis.com/matching-prefixes-in-swift-strings/
-
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 [...]
https://wadetregaskis.com/matching-prefixes-in-swift-strings/