From: Lloyd Zusman Date: 2004-08-04T09:41:05+09:00 Subject: Re: Fastest way to reverse-process a string? Joel VanderWerf writes: > Lloyd Zusman wrote: >> In a ruby program I'm writing, I want to parse a string in reverse and >> feed each of its individual characters through a state machine. >> A "hammer and tongs" solution looks like this: >> string.reverse.split(//).each { >> |ch| >> feedIntoStateMachine(ch) >> } >> However, this seems rather inefficient. Does anyone know of a faster >> algorithm for this in ruby? > > String#each_byte would avoid the creation of the array. Thank you very much. Does anyone know of a way to avoid 'reverse', as well? I discovered a 'reverse_each' method for arrays, but there doesn't seem to be a corresponding String#reverse_each_byte. Without that, I would have to incur the expense of reversing the string before applying each_byte to it. Any ideas? -- Lloyd Zusman ljz@asfast.com God bless you.