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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Way

Way

Photo of string length

string length

Related news:

News photo

Is Apple Watch SE 3 on the way? New displays reportedly in production

News photo

Woman who tricked her way into men-only Magic Circle allowed in

News photo

Rumors allege a Galaxy Tab S10 'Lite' is on the way, and a Tab S11 series shake-up