Post #2329194
2026-04-18 04:07 UTC
#SwiftLang odditity. When can't you trust string count? When you need to add a \r for reasons
let string1 = “12345\r”
let string2 = “12345\r\n”
string1.count == string2.count
Both are of size 6 which is not helpful when trying to build a network packet and need to count ALL the bytes. Grumble. I kind of remember this from way back when.
Replies (1)
-
@erithacus@mastodon.social 2026-04-18 04:50
@marchyman@sfba.social you shouldn’t use string count if you want to know the bytes. Try: string1.utf8.count string2.utf8.count