473,395 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

StreamReader problem URGENT!

Hi,

I have a problem with a CSV-file I have to read (actually I have to convert
it to a XML).

In some 'fields' of the CSV-file are some line-feed characters included (\r
??? don't know because I cannot capture them) (I suppose it are not carriage
returns). The problem is now that the StreamReader.ReadLine is considering
them too as an end-of-line, and not only the real carriage return.

As a result I am getting records that are incomplete and that is storing the
wrong data in the wrong fields on the next line when splitting the line on
the separator.

When I import the data in Access, I have the same problem, except when I set
the Text Qualifier to " (double quotes). Is there a similar thing I can do
with the StreamReader???

Any help will be appreciated very much.

Kind regards,

Christian
Nov 15 '05 #1
2 2310
christian,

according to the msdn page about StreamReader.ReadLine()
(http://msdn.microsoft.com/library/de...-us/cpref/html
/frlrfsystemiostreamreaderclassreadlinetopic.asp), the only end of line
sequences ReadLine uses are "\n" and "\r\n". the only way you'll be able
to use the ReadLine() method to get your logical lines is by ensuring that
none of your values include either of these characters. you could of
course sweep through the file and try to replace any occurrence of these
characters in your values, or you could always use one of StreamReader's
Read methods instead.

let me know if i can offer any other help.

jeff.

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 15 '05 #2
I should have been thinking of that myself; reading one char at a time and
building the line only breaking on \n\r and not on \n only. I guess I must
have been very tired yesterday evening!

Thanks!!!
Christian

"Jeff Callahan" <Je*****@online.microsoft.com> schreef in bericht
news:Ru**************@cpmsftngxa07.phx.gbl...
christian,

according to the msdn page about StreamReader.ReadLine()
(http://msdn.microsoft.com/library/de...-us/cpref/html /frlrfsystemiostreamreaderclassreadlinetopic.asp), the only end of line
sequences ReadLine uses are "\n" and "\r\n". the only way you'll be able
to use the ReadLine() method to get your logical lines is by ensuring that
none of your values include either of these characters. you could of
course sweep through the file and try to replace any occurrence of these
characters in your values, or you could always use one of StreamReader's
Read methods instead.

let me know if i can offer any other help.

jeff.

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
5
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the...
2
by: Keith Kingsley | last post by:
I'm using a StreamReader to read in several lines from an ASCII file. I'd like to know the StreamReader's "true" position-- that is, the number of bytes into the file that the StreamReader has...
3
by: Arno | last post by:
Hi, I'm using TcpClient for communication between two PC running a small piece of software. The protocol used has been designed internally and is HTTP similar (command line, headers, body). A...
3
by: Arpan | last post by:
A file can be read using only the StreamReader object like this: Dim sReader As StreamReader sReader = New StreamReader(Server.MapPath("File1.txt")) While(sReader.Peek -1)...
1
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on...
1
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData =...
7
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I am using StreamReader to read an ASCII file that contains blank lines. How can I omit reading blank lines? I tried somting like... FileStream inFile = new...
0
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ř) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.