textreader

How to open a StreamReader in ShareDenyWrite mode?

£可爱£侵袭症+ 提交于 2019-12-30 09:29:49
问题 How do i open a StreamReader with FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_DELETE? Same question, slightly expanded How do i open a StreamReader so that i can read an encoded text file, with sharing options so that another process can read the file? How do i open a StreamReader so that i can read an encoded text file, with sharing options so that another process can modify the file while i'm reading it? How do i open a StreamReader so that i can read an encoded text file, with sharing

Is there a maximum line-length in a textfile without a linebreak?

北战南征 提交于 2019-12-24 07:38:38
问题 Trying to use StreamReader or similar from C# to read and write VERY LONG lines without the linebreak. As I understand it, linebreak is still just 2 bytes (CR+LF) in a long bytearray called a file. At least thats how I am used to it in C/C++... Is this the same for C# and .net or is there some maximum length for lines without a linebreak? 回答1: There are no specific limitations in .NET, but different ways of viewing long lines may give you problems, mostly related to performance. Try to open

Tab delimited txt file reading int value from string array

岁酱吖の 提交于 2019-12-11 00:34:20
问题 I am using TextReader to read in each line of a tab delimited file. For each line that it reads I split on the tabs and populate a string array. I can then access specific positions in the string array to get the values. This works great for strings like: userWorkload.SSN = arrColumns[0]; However, I get an error message at runtime when I try to convert one of the columns to an int: userWorkload.contactHours = Convert.ToInt32(arrColumns[9]); Here is my code: List<UserWorkload> userWorkloads =

Why does IEumerator<T> affect the state of IEnumerable<T> even the enumerator never reached the end?

 ̄綄美尐妖づ 提交于 2019-12-04 11:05:24
问题 I am curious why the following throws an error message (text reader closed exception) on the "last" assignment: IEnumerable<string> textRows = File.ReadLines(sourceTextFileName); IEnumerator<string> textEnumerator = textRows.GetEnumerator(); string first = textRows.First(); string last = textRows.Last(); However the following executes fine: IEnumerable<string> textRows = File.ReadLines(sourceTextFileName); string first = textRows.First(); string last = textRows.Last(); IEnumerator<string>

Quotes in tab-delimited file

邮差的信 提交于 2019-12-04 06:40:07
问题 I've got a simple application that opens a tab-delimited text file, and inserts that data into a database. I'm using this CSV reader to read the data: http://www.codeproject.com/KB/database/CsvReader.aspx And it is all working just fine! Now my client has added a new field to the end of the file, which is "ClaimDescription", and in some of these claim descriptions, the data has quotes in it, example: "SUMISEI MARU NO 2" - sea of Japan This seems to be causing a major headache for my app. I

Why does IEumerator<T> affect the state of IEnumerable<T> even the enumerator never reached the end?

纵然是瞬间 提交于 2019-12-03 06:06:41
I am curious why the following throws an error message (text reader closed exception) on the "last" assignment: IEnumerable<string> textRows = File.ReadLines(sourceTextFileName); IEnumerator<string> textEnumerator = textRows.GetEnumerator(); string first = textRows.First(); string last = textRows.Last(); However the following executes fine: IEnumerable<string> textRows = File.ReadLines(sourceTextFileName); string first = textRows.First(); string last = textRows.Last(); IEnumerator<string> textEnumerator = textRows.GetEnumerator(); What is the reason for the different behavior? You've

Quotes in tab-delimited file

情到浓时终转凉″ 提交于 2019-12-02 09:46:25
I've got a simple application that opens a tab-delimited text file, and inserts that data into a database. I'm using this CSV reader to read the data: http://www.codeproject.com/KB/database/CsvReader.aspx And it is all working just fine! Now my client has added a new field to the end of the file, which is "ClaimDescription", and in some of these claim descriptions, the data has quotes in it, example: "SUMISEI MARU NO 2" - sea of Japan This seems to be causing a major headache for my app. I get an exception which looks like this: The CSV appears to be corrupt near record '1470' field '26 at

How to loop over lines from a TextReader?

最后都变了- 提交于 2019-11-30 23:20:41
问题 How do I loop over lines from a TextReader source ? I tried foreach (var line in source) But got the error foreach statement cannot operate on variables of type 'System.IO.TextReader' because 'System.IO.TextReader' does not contain a public definition for 'GetEnumerator' 回答1: string line; while ((line = myTextReader.ReadLine()) != null) { DoSomethingWith(line); } 回答2: You can use File.ReadLines which is deferred execution method, then loop thru lines: foreach (var line in File.ReadLines("test

In C#, how can I create a TextReader object from a string (without writing to disk)

你离开我真会死。 提交于 2019-11-30 05:33:10
I'm using A Fast CSV Reader to parse some pasted text into a webpage. The Fast CSV reader requires a TextReader object, and all I have is a string. What's the best way to convert a string into a TextReader object on the fly? Thanks! Update- Sample code- In the original sample, a new StreamReader is looking for a file called "data.csv". I'm hoping to supply it via TextBox_StartData.Text. Using this code below doesn't compile. TextReader sr = new StringReader(TextBox_StartData.Text); using (CsvReader csv = new CsvReader(new StreamReader(sr), true)) { DetailsView1.DataSource = csv; DetailsView1

How to string multiple TextReaders together?

谁说胖子不能爱 提交于 2019-11-29 14:08:38
I have 3 TextReaders -- a combination of StreamReaders and StringReaders. Conceptually, the concatenation of them is a single text document. I want to call a method (not under my control) that takes a single TextReader. Is there any built-in or easy way to make a concatenating TextReader from multiple TextReaders? (I could write my own TextReader subclass, but it looks like a fair amount of work. In that case, I'd just write them all out to a temp file and then open it with a single StreamReader.) Is there an easy solution to this that I'm missing? I just threw this together, so it's not super