J
Johnathan Wagner
Hi,
I cannot find a way to easily parse a text file. I am just starting to
learn ruby so please bear with me.
My text file looks like this:
0 8 2 9 3 0 0 4
9 2 8 3 9 3 0 2
2 3 4 9 8 8 9 0
Basically just numbers and spaces.
So far, I know how to read the file and put each line into an array.
def readfile(file)
arr = IO.readlines(file)
parsing(arr)
end
def parsing(arr)
string1 = arr[0].to_s
string2 = arr[1].to_s
string3 = arr[2].to_s
ans.each_byte {|b|p b.chr}
end
What I wanted to do is, for example, want to find all 8's and change it
to 5's.
I am stuck on how I can use the string and search each char's to find
the 8's and then change it. Also I would like to know if there is a for
loop or something to go through each array and store it into a new
string because there might be more than 3 lines. I have search through
documentations and trying to find examples but there doesn't seem to be
much help.
Any help, especially examples, would be appreciate. Thanks in advance.
I cannot find a way to easily parse a text file. I am just starting to
learn ruby so please bear with me.
My text file looks like this:
0 8 2 9 3 0 0 4
9 2 8 3 9 3 0 2
2 3 4 9 8 8 9 0
Basically just numbers and spaces.
So far, I know how to read the file and put each line into an array.
def readfile(file)
arr = IO.readlines(file)
parsing(arr)
end
def parsing(arr)
string1 = arr[0].to_s
string2 = arr[1].to_s
string3 = arr[2].to_s
ans.each_byte {|b|p b.chr}
end
What I wanted to do is, for example, want to find all 8's and change it
to 5's.
I am stuck on how I can use the string and search each char's to find
the 8's and then change it. Also I would like to know if there is a for
loop or something to go through each array and store it into a new
string because there might be more than 3 lines. I have search through
documentations and trying to find examples but there doesn't seem to be
much help.
Any help, especially examples, would be appreciate. Thanks in advance.