Questions tagged [textfieldparser]

Provides methods and properties for parsing structured text files.

57 questions
15
votes
3 answers

TextFieldParser parse CSV from string not file

Using a TextFieldParser from Microsoft.VisualBasic.FileIO it is possible to parse a CSV file like below: using (TextFieldParser parser = new TextFieldParser(CSVPath)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); …
Callum Watkins
  • 2,844
  • 4
  • 29
  • 49
6
votes
1 answer

Use AutoMapper to map a string array to an object

I am using TextFieldParser to parse a CSV file to import into a database using EntityFramework. TextFieldParser returns each line of the CSV file as a string[]. In order to save the objects, I need to build an object from each line. Is there any way…
Ryan Kohn
  • 13,079
  • 14
  • 56
  • 81
5
votes
2 answers

TextFieldParser Class

I am using the TextFieldParser Class to read comma separated value (.csv) file. Fields in this file are enclosed with double quotes like "Field1","Field2". So, to read file, I've set the HasFieldsEnclosedInQuotes property of TextFieldParser object…
optimusprime
  • 49
  • 1
  • 7
3
votes
0 answers

Can TextFieldParser and other types from the Microsoft.VisualBasic assembly be safely used in C# code?

We're looking into using the TextFieldParser class using C#, and everything seems to work as expected. However, the class is part of the Microsoft.VisualBasic assembly, and I wonder why? Surely there must be a reason why the class is in a…
Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
3
votes
1 answer

Parsing semi colon delimeter file

I have a CSV file but the delimiter is a semi colon ; and each column is enclosed with double quotes. There are also occurrences of ; in some values such as & amp; I am using TextFieldParser to parse the file. This is the sample…
Alan B
  • 2,219
  • 4
  • 32
  • 62
2
votes
1 answer

StringSplitOptions.RemoveEmptyEntries equivalent for TextFieldParser

I recently learn TextFieldParser to parse words where previously I would use string.Split to do so. And I have a question regarding the newly learned class. If we parse a message like this using string.Split with…
Ian
  • 30,182
  • 19
  • 69
  • 107
2
votes
1 answer

How to preserve CSV field whitespace for quoted field using Microsoft.VisualBasic.FileIO.TextFieldParser?

I'm parsing CSV data using Microsoft.VisualBasic.FileIO.TextFieldParser. It's very good compared to the freeware libraries I've found for parsing CSV. It does everything that I think it should WRT CSV except that it does not preserve the…
steve
  • 1,021
  • 1
  • 14
  • 29
2
votes
1 answer

TextFieldParser Not Setting EndOfData field

I have a Validate(Stream inputStream) method. This method calls several other validation methods by passing the inputStream to each one. Each of these creates a new TextFieldParser and reads/validates the file. When the first…
L_7337
  • 2,650
  • 28
  • 42
2
votes
4 answers

Ignoring CSV rows with no data

I'm surprised that I haven't seen anything about this on here (or maybe I missed it). When parsing a CSV file, if there are rows with no data, how can/should that be handled? I'm not talking about blank rows, but empty rows, for…
Relevant
  • 148
  • 1
  • 15
1
vote
1 answer

Microsoft.VisualBasic.FileIO reference

I want to use TextFieldParser in my project. For that I need using Microsoft.VisualBasic.FileIO. However Visual Studio accepts using Microsoft.VisualBasic without the FileIO. but it does not recognize the TextFieldParser class. On other forums, I…
John Ronald
  • 135
  • 8
1
vote
1 answer

How to fix: Special Characters appearing on reading csv file with TextFieldParser

I am importing a csv file, while reading it, there are special character like '�' appearing in a string which is read, how to avoid the these unicode characters. I am using TextFieldParser for parsing the data, but while reading, space between two…
1
vote
2 answers

FileIO.TextFieldParser get unaltered row for reporting on failed parse

I want to output the current row if there is an error but I'm getting a message that the current record is nothing. Here is my code: Dim currentRow As String() Using MyReader As New FileIO.TextFieldParser(filenametoimport) MyReader.TextFieldType =…
ErocM
  • 4,505
  • 24
  • 94
  • 161
1
vote
1 answer

Loop through text file "Fixed Length" using textfieldparser vb.net

**below is Textfile** 1010 IBFZEBMSKU28NOV16APTKS42490814 1015 APT55KUAPTKSS28NOV1628NOV1615.05.0016.05.00IRAPTMB254974DKUKU2297/72292700631550063155003 KUWAIT AIRWAYS 101F 01ALOTAIBI/FAHADMR 1500 CC 01CCVI4439 …
1
vote
1 answer

Object reference on array with regex.replace()

I am using the below function to import a csv file into a datatable object csvData, however i face an oject reference issue that i'd like to understand more while using Regex.Replace to remove quote marks from the data: private static DataTable…
dark.vador
  • 619
  • 1
  • 6
  • 25
1
vote
0 answers

How to calculate count of line feed or carriage return characters from a text file in C#?

I have a text file that I am reading using TextFieldParser class in c#. This file has CRLF as the newline character that I can see using Notepad++. Few lines of this file have LF as the newline character. I need to get the count of maximum…
AMeh
  • 211
  • 2
  • 6
  • 18
1
2 3 4