Get the latest tech news
The best – but not good – way to limit string length
Getting the length of a string seems simple and is something we do in our code every day. Limiting the length of a string is also extremely common in both frontend and backend code.
First, a working definition of a “ character ”: This is the human conceptual ideal of the smallest building block of most written languages: a letter, an emoji, an ideograph, a punctuation mark, a symbol, a grapheme. On one end of the spectrum, there are very short fields with visible character counts; an obvious example is the old 140-character tweet limit, which users would stare at while trying to figure out creative contractions that wouldn’t obscure their point too much. For most situations, with most string lengths, this isn’t a significant performance problem, but keep it in mind if you’re doing this inside a big loop, or with huge data, or in an HPC context.
Or read this on Hacker News