N
Nick Bo
Basically i have a document which I am opening and then i am reading
each line of the file and having to split it up into two arrays and then
into a hash in which i have to get some sort of output like this:
application/activemessage has no extensions
application/andrew-inset has extensions ez
application/applefile has no extensions
application/atom has extensions atom
application/atomcat+xml has extensions atomcat
application/atomicmail has no extensions
application/atomserv+xml has extensions atomsrv
application/batch-SMTP has no extensions
application/beep+xml has no extensions
application/cals-1840 has no extensions
I have determined that if there are no tabs in the document then the
file has no extension so what i did was an if statement in the beginning
to see if the line contained the tab if not then it would save false to
the position in the array that i was at in the each loop.
file.each_line do |line|
next if line[0] == ?#
next if line == "\n"
string = line
if string.include?("\t") == false
mimeValue = false
mimeKey=string.split
else
#THIS IS WHERE MY ISSUE IS NOW
mimeKey, mimeValue = string.split("\t\t\t")
end
My problem now that sometimes teh document is split by tabs changing in
number one line may have 3 tabs other may have 5 and one might just have
just 1. So I am in a rut now How do i determine how many tabs are in
the line(string variable) thus so i can split the two parts into their
appropriate arrays. I was thinking I could do some kind of recurssion
which would test to see if tab and if so then add 1 to count and then be
able to do something like
mimeKey, mimeValue = string.split(#{tabCount}*("\t"))
I know there is alot in my message so here is a summary:
HOW TO COUNT \t IN A STRING THEN SPLIT BY THAT NUMBER OF \t
each line of the file and having to split it up into two arrays and then
into a hash in which i have to get some sort of output like this:
application/activemessage has no extensions
application/andrew-inset has extensions ez
application/applefile has no extensions
application/atom has extensions atom
application/atomcat+xml has extensions atomcat
application/atomicmail has no extensions
application/atomserv+xml has extensions atomsrv
application/batch-SMTP has no extensions
application/beep+xml has no extensions
application/cals-1840 has no extensions
I have determined that if there are no tabs in the document then the
file has no extension so what i did was an if statement in the beginning
to see if the line contained the tab if not then it would save false to
the position in the array that i was at in the each loop.
file.each_line do |line|
next if line[0] == ?#
next if line == "\n"
string = line
if string.include?("\t") == false
mimeValue = false
mimeKey=string.split
else
#THIS IS WHERE MY ISSUE IS NOW
mimeKey, mimeValue = string.split("\t\t\t")
end
My problem now that sometimes teh document is split by tabs changing in
number one line may have 3 tabs other may have 5 and one might just have
just 1. So I am in a rut now How do i determine how many tabs are in
the line(string variable) thus so i can split the two parts into their
appropriate arrays. I was thinking I could do some kind of recurssion
which would test to see if tab and if so then add 1 to count and then be
able to do something like
mimeKey, mimeValue = string.split(#{tabCount}*("\t"))
I know there is alot in my message so here is a summary:
HOW TO COUNT \t IN A STRING THEN SPLIT BY THAT NUMBER OF \t