我在使用ruby 2.5.1进行CSV解析时遇到了一个罕见的问题。 CSV文件是机械化的txt文件。使用ruby 2.3.3或ruby 2.4.4解析此文件非常有效。但是我无法使用ruby 2.5.1解析文件。我需要更新任何内容才能在2.5.1中进行解析吗?
下面是我的代码。
csv_header = ["Rep Date", "Or No", "Qw Type", "Sett No", "Order Date", "AS Code", "ZCV", "Amount", "Qty", "BN Code", "AX Code", "User Id", "QW No", "QX Code", "WE No", "MN Code", "KL Name", "IO Id", "A AS", "DD Unit", "DD Amt", "DD Flag", "Remarks", "RRR", "KK Ref No", "TY Type", "SS Regn No", "SR Reg Date", "SU Code", "PPP", "QQQ DEC", "NM Flag", "DP Trans", "O Type"].freeze
response = agent.submit(form, button)
parsed = CSV.parse(response.body, col_sep: '|', write_headers: true, headers: csv_header)
# in ruby 2.3.3
parsed.count # 1523
# in ruby 2.5.1
parsed.count # 0
# data in response body looks like bellow
2018-12-05|234|T3|1819166|2018-12-03|489-AB|INFJF5|10000.0000|0|11887|RPBRANCH|1188701|20307754|489|PT2051|46A4CUM|AS Kapoor ||41.3500|241.8380|10000.0000|Y||0.0000|6662747|SP|3674288|24/10/2018|||N|Y|P|ASA|
2018-12-04|525|T3|1812366|2018-12-03|489-RR|INFJF5|1000.0000|0|11887|RPBRANCH|1188701|21551474|489|SW145481|VTI4JPA|Prasad P||41.3500|24.1840|1000.0000|Y||0.0000|78208832|STP|68798|24/09/2018|||N|Y|P|ASB|
我用CSV::VERSION
检查了CSV的版本,在两个控制台中都显示了"2.4.8"
。