From: Yukihiro Matsumoto Date: 2007-11-03T00:12:59+09:00 Subject: Re: Didn't find String#subseq Hi, In message "Re: Didn't find String#subseq" on Fri, 2 Nov 2007 04:20:23 +0900, Wolfgang N�dasi-Donner writes: |Here is exactly the problem possible I mentioned... | |class String | def byte_range(from, to) | e = self.encoding | r = self.force_encoding('ascii')[from..to] | r.force_encoding(e) |end | |puts "b�h!".byte_range(3,4) # => "h!" |puts "b�h!".byte_range(2,4) # ! nonsense ! | |..., so I think it will be a good idea to have a check method. We will provide a validation method, name not fixed yet. |But, and this is very important for these kind of usage, how does Ruby 1.9 |handle the following... | |s = "a�o�u�" * 5000 |29999.downto(29000){|i|puts s[i]} | |..., if s.encoding is utf-8? - Does Ruby calculate the character positions for |each access via [], or will the positions be stored for later usage after first |calculation? Ruby calculate the position each time if encoding is variable character width. It may cause performance problem, but less often than you've expect. matz.