From: Alex DeCaria Date: 2010-04-13T20:25:56+09:00 Subject: Re: how to delete the first two characters of each row? Pen Ttt wrote: > how to delete the first two characters of each row? > i want to delete the first two characters of each row in file > /home/pt/test/mtp.txt > > > io=open("/home/pt/test/mtp.txt","r") > io1=open("/home/pt/test/mtpback.txt","w") > while line=io.gets > ioput=line.delete("/^..../") > io1.write(ioput) > end > > when i open /home/pt/test/mtpback.txt,there is not what i want,where is > wrong? You could do io=open("/home/pt/test/mtp.txt","r") io1=open("/home/pt/test/mtpback.txt","w") while line=io.gets ioput=line[2..line.length] # extract substring without first two characters io1.write(ioput) end -- Posted via http://www.ruby-forum.com/.