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

Justin Collins:

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

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

>> polish =3D 'W trosce o byt i przysz=C5=82o=C5=9B=C4=87 naszej Ojczyzny'
=3D> "W trosce o byt i przysz=C5=82o=C5=9B=C4=87 naszej Ojczyzny"
>> polish[0, 27]
=3D> "W trosce o byt i przysz=C5=82o\305"
>> polish[0, 30]
=3D> "W trosce o byt i przysz=C5=82o=C5=9B=C4=87"

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

>> polish =3D 'W trosce o byt i przysz=C5=82o=C5=9B=C4=87 naszej Ojczyzny'
=3D> "W trosce o byt i przysz=C5=82o=C5=9B=C4=87 naszej Ojczyzny"
>> polish[0, 27]
=3D> "W trosce o byt i przysz=C5=82o=C5=9B=C4=87"

-- Shot
--=20
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=
=3a2t
-----END PGP SIGNATURE-----

--tjCHc7DPkfUGtrlw--

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¡Çt 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFJGXsbi/mCfdEo8UoRAo6YAJ9tVYjjOQs8xZhK8soFhL/cDkIiXwCfSEd6
JqtDm3ADZWe2ZQ/8tgUqnwU=
=3a2t
-----END PGP SIGNATURE-----