From: "Esteban Manchado Velázquez" Date: 2006-07-31T06:51:35+09:00 Subject: Re: Howto Delete 3 Leftmost Characters --aVD9QWMuhilNxW9f Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jul 31, 2006 at 06:30:13AM +0900, Skeets wrote: > i'm sure this is easy, but i've gone through Pickaxe's string methods, > searched the web and searched the groups, and i can't figure out how to > do this in Ruby. >=20 > i grep a file and it returns the following string: >=20 > #ip 127.0.0.1 >=20 > i now want to get rid of "#ip" so i can then strip the remaining string > to get rid of spaces. >=20 > however, i can't find out how to delete the 3 leftmost characters - in > this case "#ip". "#ip 127.0.0.1"[3..-1] # =3D> " 127.0.0.1" "#ip 127.0.0.1"[4..-1] # =3D> "127.0.0.1" But you're probably better off using regular expressions instead of fixed indices: "#ip 127.0.0.1".sub(/^#ip\s+/, '') # =3D> "127.0.0.1" That is, "remove, from the beginning of the line, '#ip' followed by one or more space characters (be them spaces, tabs or whatever)". If you don't know regular expressions, _and_ you're into text processing, I recommend you to = go and read some book about regular expressions and practice a little (under Linux there are a couple of handy utilities for that; I'm sure there must be also for other platforms). Regards, --=20 Esteban Manchado Vel=E1zquez - http://www.foton.es EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es --aVD9QWMuhilNxW9f Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQFEzSnThYgK5b1UDsERAhvxAKCBujlym/pqzSmCxF8uBrJUSj9o6gCfXdO5 zpB70fF84zLjRveAZ5UnEG0= =4jfG -----END PGP SIGNATURE----- --aVD9QWMuhilNxW9f--