--tjCHc7DPkfUGtrlw
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Justin Collins:

> a_long_string =  "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
> Pellentesque pulvinar turpis a nisi. Cras id elit. Aliquam vitae pede nec 
> lacus elementum lacinia. Ut aliquam ehicula sem."
> limit = 86
> a_long_string[0, limit] << "..."    #=> "Lorem ipsum dolor sit amet, 
> consectetuer adipiscing elit. Pellentesque pulvinar turpis..."

Note that in Ruby 1.8 String#[] doesn work on chars, but bytes,
which means the above is not reliable for multibyte strings like UTF-8:

>> polish = 'W trosce o byt i przyszo naszej Ojczyzny'
=> "W trosce o byt i przyszo naszej Ojczyzny"
>> polish[0, 27]
=> "W trosce o byt i przyszo\305"
>> polish[0, 30]
=> "W trosce o byt i przyszo"

In Ruby 1.9 String#[] works on chars, so the above works as expected:

>> polish = 'W trosce o byt i przyszo naszej Ojczyzny'
=> "W trosce o byt i przyszo naszej Ojczyzny"
>> polish[0, 27]
=> "W trosce o byt i przyszo"

-- Shot
-- 
Making the choice to roll your own always is a tough one,
because it breaks Programmer's Rule Number 42, which clearly
states, "Every problem has been solved. It is Open Source.
And it is the first link on Google."        -- Ara T. Howard

--tjCHc7DPkfUGtrlw
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFJGXsbi/mCfdEo8UoRAo6YAJ9tVYjjOQs8xZhK8soFhL/cDkIiXwCfSEd6
JqtDm3ADZWe2ZQ/8tgUqnwU:2t
-----END PGP SIGNATURE-----

--tjCHc7DPkfUGtrlw--