2 ms·
I don't know why people aren't asking the same question for JavaScript. Certainly, that call is going to cause trouble sometimes. Just try it on the string "<sm
by mikeash 11y ago
I don't know why people aren't asking the same question for JavaScript. Certainly, that call is going to cause trouble sometimes. Just try it on the string "<smiley emoji> I love it." (HN is unhappy with emoji, apparently. Surprise! Stuff that doesn't fit into UTF-16 often breaks all sorts of things.) The results are rather unexpected. But it works often enough that I assume people just don't really think about it much.
That's the trouble with string manipulation: it's usually easy to make a 99% solution and hard to make a 100% solution. Swift is attempting to prod you into the 100% solution by making the 99% solution more difficult, and the 100% solution maybe a bit easier.