textfieldparser

Parsing semi colon delimeter file

馋奶兔 提交于 2020-01-02 08:13:24
问题 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 data: "A001";"RT:This is a tweet"; "http://www.whatever.com/test/module & amp;one" For the above example , I am getting more columns/fields than what I should get. Field[0] = "A001" Field[1] = "RT:This is a tweet" Field[2] = "http://www.whatever.com/test/module&amp"

How do we distinguish between managed and unmanaged resources in C#? Is TextFieldParser unmanaged?

醉酒当歌 提交于 2019-12-23 04:47:14
问题 I recently learned how to use Microsoft.VisualBasic.FileIO.TextFieldParser to parse a text input. In the example given to me, the TextFieldParser is called using the keyword using using (var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(new StringReader(str))) Though after some further researches, I notice that the practice of using using keyword for TextFieldParser is not universal. As far as I understand, .Net Framework has both managed and unmanaged resource. And when we use

Stream is disposing before EndOfData is true

廉价感情. 提交于 2019-12-21 22:44:09
问题 I am writing a method that connects to an FTP, reads a csv file into a stream then uses a TextFieldParser to process the data. It's all working except for an issue I'm getting when it gets about halfway through reading the CSV suddenly I get an ObjectDisposedException exception. I've tried passing both the StreamReader & TextReader to the TextFieldParser but both result in the same problem. Should I be downloading the CSV to a temporary local directory and then reading that or is there no

Object reference on array with regex.replace()

筅森魡賤 提交于 2019-12-13 19:17:39
问题 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 Gettabledata(string cpath) { DataTable csvData = new DataTable(); try { using (TextFieldParser csvReader = new TextFieldParser(cpath)) { csvReader.SetDelimiters(new string[] { "," }); csvReader.HasFieldsEnclosedInQuotes = true; string[] colFields =

StringSplitOptions.RemoveEmptyEntries equivalent for TextFieldParser

非 Y 不嫁゛ 提交于 2019-12-12 20:06:59
问题 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 StringSplitOptions.RemoveEmptyEntries string message = "create myclass \"56, 'for better or worse'\""; //have multiple spaces string[] words = message.Split(new char[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries); Then we will get words which contain three elements like this:

How to split a text lines by fixed width C#

落爺英雄遲暮 提交于 2019-12-11 21:26:17
问题 Does anyone know how to split this file 1 TESTAAA SERNUM A DESCRIPTION 2 TESTBBB ANOTHR ANOTHER DESCRIPTION 3 TESTXXX BLAHBL Each column has a fixed width and I'm planning to do it with a regex but I don't know how to do it exactly. Having {id} {firsttext} {serialhere} {description} 4 22 6 30+ Someone recommend with a pattern like this (.{4})(.{22})(.{6})(.+)? then split it by split(' ') but the user stated that this won't work with a column has no value, but even that, he didn't do any

Microsoft.VisualBasic.FileIO reference

≡放荡痞女 提交于 2019-12-11 14:46:54
问题 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 read I should add Microsoft.VisualBasic reference. I am not able to work out how to do this, since the window of Reference Manager is completely blank, so I do not have any option to chose from. Any help ? 回答1: The "Add Reference" dialog that you

How to keep quotes when parsing csv file?

醉酒当歌 提交于 2019-12-11 05:57:08
问题 I am using Microsoft.VisualBasic.FileIO.TextFieldParser to read a csv file, edit it , then parse it. The problem is the quotes are not being kept after parsing. I tried using parser.HasFieldsEnclosedInQuotes = true; but it does not seem to keep the quotes for some reason. This issue breaks when a field contains a quote for example : Before "some, field" After some, field As two seperate fields Here is my method public static void CleanStaffFile() { String path = @"C:\file.csv"; String dpath =

Parsing semi colon delimeter file

一笑奈何 提交于 2019-12-05 23:25:26
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 data: "A001";"RT:This is a tweet"; "http://www.whatever.com/test/module & amp;one" For the above example , I am getting more columns/fields than what I should get. Field[0] = "A001" Field[1] = "RT:This is a tweet" Field[2] = "http://www.whatever.com/test/module&amp" Field[3] = "one" This is my code. What changes need to be done to handle such scenario? using (var