Daniel M. wrote:
I’ll point you at my solution to ruby quiz #83: (short but unique)
How would you write the method string_similarity without access to
each character? (This method computes the length of the longest
How would you compute the Levenshtein distance (edit distance) between
two strings without access to each character?
I’ll grant that I don’t have enough imagination and that there are
you want character access. But it seems to me that the main use case is
something like this:
str = “cogito ergo sum”
i = str.index("") + 3
j = str.index("",i)
and for that common case, regexes are far more appropriate:
Advocating regexes-only for character manipulation is certainly extreme.
just saying that byte access and character access needs to have
semantics. If you look at the current ruby String API, bytes are
through integer positions and characters are accessed through regexes.
are char APIs are quite distinct, it’s just that everybody is using the
and expecting to get characters as a result.
From what I understand (and please correct me if I’m wrong), ruby2 will
that by changing the api so that integer positions represent characters
of bytes. For binary strings, those two concepts map to the same reality
won’t be such a backward-incompatible change. I just wonder what will be
behavior of str. Will it return a 0…255 integer in the case of
and a 1-character string in the case of encoding-set string? Now that
an API nightmare.
How would you pull strings out of a file with fixed-width fields?
With regular expressions? Really? What if you had a hundred fields?
Hmm, fixed width records and fields were created for the purpose of fast
to data, i.e. seek to position recnum*reclength and extract reclength
they only make sense in the case of single-byte characters. So this is
case of byte access.