Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
array problem with sorting - maybe easy but not for me
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Mmcolli00 Mom, post: 4628046"] This code reads in a text file with comma separated values. Problem is, some values are missing and it causing other values to ride up the list. I want to replace those values with string 'no value' then adjust there others if the next value is not listed on the second iteration of the array. I am new to learning programming. patientrecords.txt 1,PersonID,PersonID 2,ID,ID 3,LastName,Social Security #<-insert 'no value' 4,Social Security, Address #<-change array[2] Social Security 5,Address,UniqueID #<-change array[2] to Address 6,UniqueID,Potassium #<-change array[2] to UniqueID ************************************************** File.open('patientrecords.txt', 'r') do |temp| array = [] temp.each_line do |line| array = line.chomp.split(",",0) nextVal = array[0].to_i + 1 line.each_line do |n1| if array[1] != array[2] then if array[0] != nextVal then array[2] = "no value" end #array[2] = array[1] #populates the array[2] end end puts array[0]+","+array[1]+","+array[2] end end Attachments: [URL]http://www.ruby-forum.com/attachment/3148/patientrecords.txt[/URL] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
array problem with sorting - maybe easy but not for me
Top