Instead of capturing each data element one at a time with separate
user.scan's, it's easier to create a match object from a single
regular expression that contains match groups. You can then access
the results of the match group by using $1, $2, etc.
Try this:
Cemployee=Array.new
CemployeeID=Array.new
CemployeeName=Array.new
counter=0
CemployeeS=" "
File.open("D:\\finance.txt").each { |user|
m = /^([C]\d+)\s(\w+,\s?\w+)/.match(user)
if m
CemployeeID[counter]=$1
CemployeeName[counter]=$2
puts "Name: #{CemployeeName[counter]} ID:
#{CemployeeID[counter]}"
counter+=1
end
}
Hope that helps-
Brian