From: Milo Luo Date: 2009-12-27T15:32:09+09:00 Subject: Re: How to truncate the spaces in the front of a line Phillip Gawlowski wrote: > On 27.12.2009 06:06, Milo Luo wrote: > >> Cool. I should really have a try. :) >> Thank you, Phillip. You really help me a lot. > > You are very welcome. :) > > Asking, then answering questions are a great way to learn, so I'm glad > to be of assistance. Hi, Phillip Here comes the new problem. I want to use this gsub to substitue the spaces in the front of some lines in a XML file. I have tried your method with string variable, but it seems not work for this XML file. I check this file very carefully, I found the spaces before some lines are 3 tabs. require 'fileutils' #Some basic variables LPT_FILE_NAME="abc.xml" File.file? LPT_FILE_NAME #Open XML file f = File.open(LPT_FILE_NAME) begin while (line = f.readline) line.chomp if line =~ // while ( line !~ /<\/Properties>/ && line = f.readline) #puts line.gsub /^\/t+/,"" if line =~ // if line =~ // name = line..gsub /^\/s+/,"" puts name end end end end rescue EOFError f.close end The abc.xml file should simplely look like this: TestData 1 100 Could you give me a hand? Thank you. Milo -- Posted via http://www.ruby-forum.com/.