如何根据不同数组行中值的比较添加列 [英] How do I add column based on comparison of values in different rows of array

查看:104
本文介绍了如何根据不同数组行中值的比较添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拥有以下CSV文件:

首页|上一页|电子邮件| EmpID | SupervisorID |城市|

Frank | Rizzo | frank.rizzo@gmail.com | 99999 | 88888 | Yonkers |
Sol | Rosenberg | sol.rosenberg@msn.com | 88888 | 56565 | Queens |



理想情况下需要要将第二个数字列与第一个数字列进行比较,如果找到匹配项,请抓取匹配项的电子邮件并附加该列。由于上面有匹配,它会产生:



Frank | Rizzo | frank.rizzo@gmail.com | 99999 | 88888 | Yonkers | sol.rosenberg@msn .com |



我尝试过:



尝试重复来源文件和两个数组的匹配,但这是愚蠢的,必须是一个阵列的方式。使用两个不同的索引并循环通过CSV文件生成的同一个数组?

解决方案

Quote:

使用两个不同的索引并循环通过CSV文件生成的同一个数组?

完全正确。





多数民众赞成'用两个嵌套循环完成:

  for 


< blockquote> i = 0 ;


i <(

Have a CSV file like this:
First|Last|Email|EmpID|SupervisorID|City|
Frank|Rizzo|frank.rizzo@gmail.com|99999|88888|Yonkers|
Sol|Rosenberg|sol.rosenberg@msn.com|88888|56565|Queens|

Ideally want to compare the second numeric column to the first numeric column and if it finds a match, grab the email of the match and append that column. Since the above has a match, it would generate:

Frank|Rizzo|frank.rizzo@gmail.com|99999|88888|Yonkers|sol.rosenberg@msn.com|

What I have tried:

Tried duplicating source file and doing a match of two arrays, but that's silly, got to be a way with one array. Use two different indexes and loop through same single array generated from CSV file?

解决方案

Quote:

Use two different indexes and loop through same single array generated from CSV file?

Exactly.


Thats' tipically done with two nested loop like:

for (


i = 0;


i < (


这篇关于如何根据不同数组行中值的比较添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆