Greg Wooledge (2018-04-04): > Does it count if we want the 1st char, then the 2nd char, then the 3rd > char, then the 4th char, and so on? Or is that not blue enough?
It is not out of the blue, it is in sequence. > How about the last char? Or the last two chars? Ditto. > Or all chars starting > just after the last slash or period? There is no n here, you have to first look for the last slash. > How about performing a checksum like the > <https://en.wikipedia.org/wiki/Luhn_algorithm> on a user input string > which is supposed to be a 10-digit > <https://en.wikipedia.org/wiki/National_Provider_Identifier> ? Again, in sequence. > Might it be useful to check the length of an input string before > bothering to decompose it into individual digits and perform the > arithmetic? And to check it is made of all digits. Checking the length is only a byproduct. > And here, by "length", I mean "number of characters". > You can see how that might be a handy thing, right? Still, no. > Length as in "number of bytes required to store it" is also an > important value, of course. You have to compute it to store it, indeed. > Character length is also useful when displaying strings on > CHARACTER-ORIENTED OUTPUT MEDIA. Like terminals. You know, those > things that Unix-like systems use all the time? How else are you > going to space-pad the fields so that the output columns line up, > if you don't know how many extra spaces you need, because you don't > know the length of the string? I do not know. Please tell me, how do you handle control characters, escape sequence, double-width characters, etc., without walking the string in sequence? > (It's frankly disturbing to me that when I talked about length being > relevant when printing strings, you immediately jumped to "pixels" and > "fonts". This tells me that you no longer accept the terminal as your > lord and savior. If you ever did.) I do not have a "lord and savior". I use the terminal a lot, but I am aware of the hidden complexities. > All of these things matter, and are real, and don't necessarily indicate > "botched design". All these things matter, but they do not require random access in a string by char number. Regards, -- Nicolas George
signature.asc
Description: Digital signature