简体   繁体   English

使用Lumenworks CSV Parser提取整行/整行

[英]Extract whole row/line using Lumenworks CSV Parser

How do I read the whole row while using LumenWorks CVS parser? 在使用LumenWorks CVS解析器时如何读取整行? So far am only able to read entry by entry but not the whole row. 到目前为止,我只能通过输入而不是整行读取条目。 ie if a row is a,b,c,d,e,f , am able to pluck out each individual alphabet. 即如果一行是a,b,c,d,e,f ,我能够拔出每个单独的字母表。 However, I want to be able to read the whole row 但是,我希望能够阅读整行

Currently I have: 目前我有:

my_csv = New CsvReader(New StreamReader(file_path), False, ",", resetPoint)
field_count = my_csv.FieldCount
While my_csv.ReadNextRecord()
    'process the data here
    'This code will process each individual alphabet in one row

The above reads each individual alphabet. 以上读取每个单独的字母表。 What I want is to have something like 我想要的是拥有类似的东西

row = my_csv.row

Is this option available or something similar? 这个选项是可用的还是类似的?

'EDITED' “已修改”

When you have basic VB programming skills like me, this is what you come up with to solve the problem 当你拥有像我这样的基本VB编程技能时,这就是你想出来解决问题的方法

Dim my_string As String = ""
        For x As Integer = 0 To my_csv.FieldCount - 1
            my_string += my_csv(x).ToString.Trim + ","
        Next
        my_string = Mid(my_string, 1, Len(my_string) - 1)
        Return my_string

By all means use the code in the marked answer. 一定要使用标记答案中的代码。 Its super elegant! 它超级优雅!

I haven't found anything available, but this should work: 我没有找到任何可用的东西,但这应该有效:

VB: VB:

Dim rowFields = Enumerable.Range(0, my_csv.FieldCount).
   Select(Function(field) my_csv(CInt(my_csv.CurrentRecordIndex), field))
Dim line As String = String.Join(my_csv.Delimiter.ToString(), rowFields)

C#: C#:

var rowFields = Enumerable.Range(0, my_csv.FieldCount)
    .Select(field => my_csv[(int)my_csv.CurrentRecordIndex, field]);
string line = string.Join(my_csv.Delimiter.ToString(), rowFields);

I found a method using the CopyCurrentRecordTo(array) method, which seems to be marginally faster (a few seconds) the wider (more columns) a file is: 我找到了一个使用CopyCurrentRecordTo(array)方法的方法,该方法似乎比文件更宽(更多列)更快(几秒钟):

C#: C#:

string[] currentRow = new string[csv.FieldCount];
while (csv.ReadNextRecord())
{
  csv.CopyCurrentRecordTo(currentRow);
  var line = string.Join(csv.Delimiter.ToString(), currentRow);
}

VB (this is from Telerik converter, beware): VB(这是来自Telerik转换器,请注意):

Dim currentRow As String() = New String(csv.FieldCount - 1) {}
While csv.ReadNextRecord()
    csv.CopyCurrentRecordTo(currentRow)
    Dim line = String.Join(csv.Delimiter.ToString(), currentRow)
End While

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM