T
Taylor Strait
I have files with city names which have one or two trailing whitespaces:
Adelanto <-
Agoura Hills <-
Alameda <-
Albany <-
Alhambra <-
Aliso Viejo <-
My method just iterates and strips!
def trim(state)
diskfile = File.new(state + "-cleaned.txt", "w")
$stdout = diskfile
IO.foreach(state + ".txt") do |line|
line.strip!
puts line
end
diskfile.close
$stdout = STDOUT
end
The output successfully removes leading whitespace but not trailing
whitespace. What am I doing wrong? I would chop! but the number of
trailing whitespace characters varies and my attempt at a while loop to
check and chop! was unsuccessful.
Adelanto <-
Agoura Hills <-
Alameda <-
Albany <-
Alhambra <-
Aliso Viejo <-
My method just iterates and strips!
def trim(state)
diskfile = File.new(state + "-cleaned.txt", "w")
$stdout = diskfile
IO.foreach(state + ".txt") do |line|
line.strip!
puts line
end
diskfile.close
$stdout = STDOUT
end
The output successfully removes leading whitespace but not trailing
whitespace. What am I doing wrong? I would chop! but the number of
trailing whitespace characters varies and my attempt at a while loop to
check and chop! was unsuccessful.