I use streamReader to read files from hard drive. Some files which I read
have spaces at the end of line. However whatever code I use
StreamReader1 = System.IO.File.OpenText(file)
or
StreamReader1 = New System.IO.StreamReader(file)
and then
StreamReader1.ReadToEnd()
or
StreamReader1.ReadLine()
I am losing spaces in the response. What I need to change to read all data.
Aleks Kleyn 12 3104
Aleks Kleyn wrote:
I use streamReader to read files from hard drive. Some files which I
read have spaces at the end of line. However whatever code I use
StreamReader1 = System.IO.File.OpenText(file)
or
StreamReader1 = New System.IO.StreamReader(file)
and then
StreamReader1.ReadToEnd()
or
StreamReader1.ReadLine()
I am losing spaces in the response. What I need to change to read all data.
Aleks Kleyn
Are you sure that you are losing the spaces when reading the text from
the file? Have you verified that the file is actually containing those
spaces, and that they really are space characters?
It makes no sense that anything would be removed when reading a file.
What do you do with the text after reading it, and how do you determine
that there are spaces missing?
--
Göran Andersson
_____ http://www.guffa.com
"Aleks Kleyn" <Al*********@MailAps.orgschrieb:
>I use streamReader to read files from hard drive. Some files which I read have spaces at the end of line. However whatever code I use
StreamReader1 = System.IO.File.OpenText(file)
or
StreamReader1 = New System.IO.StreamReader(file)
and then
StreamReader1.ReadToEnd()
or
StreamReader1.ReadLine()
I am losing spaces in the response. What I need to change to read all
data.
How do you take a look at the data read from the file?
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
It is very simple. I know place where line of file has spaces in the end
(for instance "ba ". Then I put break point at place where I read the
file, copy the value of variable into notepad and see that after charecter
'a' next line follows imediately. Discovered I this because stream was
procede not way as I expected.
Aleks Kleyn
"Aleks Kleyn" <Al*********@MailAps.orgwrote in message
news:LS************@newsfe12.lga...
It is very simple. I know place where line of file has spaces in the end
(for instance "ba ". Then I put break point at place where I read the
file, copy the value of variable into notepad and see that after charecter
'a' next line follows imediately. Discovered I this because stream was
procede not way as I expected.
I would expect this is a feature of the streamreader. Try opening the file
using a filestream instead.
>
Aleks Kleyn
On Mar 19, 12:42 am, "Michael C" <nos...@nospam.comwrote:
"Aleks Kleyn" <Aleks_Kl...@MailAps.orgwrote in message
news:LS************@newsfe12.lga...
It is very simple. I know place where line of file has spaces in the end
(for instance "ba ". Then I put break point at place where I read the
file, copy the value of variable into notepad and see that after charecter
'a' next line follows imediately. Discovered I this because stream was
procede not way as I expected.
I would expect this is a feature of the streamreader. Try opening the file
using a filestream instead.
Aleks Kleyn
No, something else must be happening here. I use StreamReader all the
time to read text files and spaces at the ends of the line are always
read.
Are the spaces at the end of the line followed by both a carriage
return and linefeed character?
Can you show us a simple program that duplicates the error.
Chris
Aleks Kleyn wrote:
It is very simple. I know place where line of file has spaces in the end
(for instance "ba ". Then I put break point at place where I read the
file, copy the value of variable into notepad and see that after
charecter 'a' next line follows imediately. Discovered I this because
stream was procede not way as I expected.
Aleks Kleyn
Either the spaces aren't there from the start, or you have to do
something that removes them.
I tried this code:
Dim r As StreamReader
r = File.OpenText("d:\temp\test.txt")
s = r.ReadToEnd
r.Dispose()
With the file test.txt containing four lines:
====================
asdf
b
asdfasdf
qwerty
====================
I put a breakpoint after the code and looked at the contents of the s
variable, and the spaces are there.
--
Göran Andersson
_____ http://www.guffa.com
I think it has carriage
return and linefeed character, because i edited it by ms studio, and it
warns if something is absent.
..
The code is
Dim TextStream As System.IO.StreamReader
If (My.Computer.FileSystem.FileExists(fpath)) Then
TextStream=new System.IO.StreamReader(fpath,True)
'TextStream = System.IO.File.OpenText(fpath)
HtmString = TextStream.ReadToEnd()
TextStream.Close()
Both cases, comented and uncomented give the same answer.
Aleks Kleyn wrote:
I think it has carriage
return and linefeed character, because i edited it by ms studio, and it
warns if something is absent.
Then it's most likely that program that removes the spaces when you save
the file.
Open the file in Notepad and check if the spaces are there. It's a plain
text editor without any syntax formatting features, so it won't remove
characters for you.
--
Göran Andersson
_____ http://www.guffa.com
Yesterday after your email I thought that may be problem that I use
asp.net code and you visual basic. I repeat this code in visual basic
and got the same result (by the way I do not see spaces in your email,
at least they disapear in response windows; may be this server has the
same problem). Today I tried in VB next code
Dim HtmString As String
Dim TextStream As System.IO.StreamReader
Dim fso As Object, TextStream1 As Object
If (My.Computer.FileSystem.FileExists(fpath)) Then
TextStream = New System.IO.StreamReader(fpath, True)
'TextStream = System.IO.File.OpenText(fpath)
HtmString = System.IO.File.ReadAllText(fpath)
HtmString = TextStream.ReadToEnd()
TextStream.Close()
fso = CreateObject("Scripting.FileSystemObject")
TextStream1 = fso.OpenTextFile(fpath)
HtmString1 = TextStream1.ReadAll()
End If
HtmString and HtmString1 were different and HtmString1 has all spaces.
Aleks Kleyn Al*********@MailAPS.org wrote:
Yesterday after your email I thought that may be problem that I use
asp.net code and you visual basic.
What programming language are you using then? ASP.NET is not a
programming language, just a platform. I assumed that you were using
VB.NET as you are posting in the VB.NET newsgroup.
I repeat this code in visual basic
and got the same result (by the way I do not see spaces in your email,
at least they disapear in response windows; may be this server has the
same problem).
You are right, the spaces disappeared from the post. Each line in the
file was padded with spaces to eight characters in length.
Today I tried in VB next code
Dim HtmString As String
Dim TextStream As System.IO.StreamReader
Dim fso As Object, TextStream1 As Object
If (My.Computer.FileSystem.FileExists(fpath)) Then
TextStream = New System.IO.StreamReader(fpath, True)
'TextStream = System.IO.File.OpenText(fpath)
HtmString = System.IO.File.ReadAllText(fpath)
HtmString = TextStream.ReadToEnd()
TextStream.Close()
fso = CreateObject("Scripting.FileSystemObject")
TextStream1 = fso.OpenTextFile(fpath)
HtmString1 = TextStream1.ReadAll()
End If
HtmString and HtmString1 were different and HtmString1 has all spaces.
Aleks Kleyn
The equivalent of the FileSystemObject code would be:
HtmlString = System.IO.ReadAllText(path, System.Text.Encoding.ASCII)
--
Göran Andersson
_____ http://www.guffa.com
On Mar 20, 2:44 pm, Göran Andersson <g...@guffa.comwrote:
Aleks_Kl...@MailAPS.org wrote:
Yesterday after your email I thought that may be problem that I use
asp.net code and you visual basic.
What programming language are you using then? ASP.NET is not a
programming language, just a platform. I assumed that you were using
VB.NET as you are posting in the VB.NET newsgroup.
I repeat this code in visual basic
and got the same result (by the way I do not see spaces in your email,
at least they disapear in response windows; may be this server has the
same problem).
You are right, the spaces disappeared from the post. Each line in the
file was padded with spaces to eight characters in length.
Today I tried in VB next code
Dim HtmString As String
Dim TextStream As System.IO.StreamReader
Dim fso As Object, TextStream1 As Object
If (My.Computer.FileSystem.FileExists(fpath)) Then
TextStream = New System.IO.StreamReader(fpath, True)
'TextStream = System.IO.File.OpenText(fpath)
HtmString = System.IO.File.ReadAllText(fpath)
HtmString = TextStream.ReadToEnd()
TextStream.Close()
fso = CreateObject("Scripting.FileSystemObject")
TextStream1 = fso.OpenTextFile(fpath)
HtmString1 = TextStream1.ReadAll()
End If
HtmString and HtmString1 were different and HtmString1 has all spaces.
Aleks Kleyn
The equivalent of the FileSystemObject code would be:
HtmlString = System.IO.ReadAllText(path, System.Text.Encoding.ASCII)
--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -
- Show quoted text -
i using visual basic.net. There is no difference where I use it: in
asp or desktop (the only difference that there is no global vars like
we use them in desktop). Today's test showed this one more time.
Spaces do not disappear for reason of posting because all code runs on
the server.
You probably mean System.IO.File.ReadAllText, because IO does not have
such method.
Adding your encoding turned disappeared spaces to question mark, so
they are not really spaces. The question now is to find good encoding,
but this is no problem. It is interesting, because file was prepared
by ms word.
Thank you very much Al*********@MailAPS.org wrote:
On Mar 20, 2:44 pm, Göran Andersson <g...@guffa.comwrote:
>Aleks_Kl...@MailAPS.org wrote:
>>Yesterday after your email I thought that may be problem that I use asp.net code and you visual basic.
What programming language are you using then? ASP.NET is not a programming language, just a platform. I assumed that you were using VB.NET as you are posting in the VB.NET newsgroup.
>>I repeat this code in visual basic and got the same result (by the way I do not see spaces in your email, at least they disapear in response windows; may be this server has the same problem).
You are right, the spaces disappeared from the post. Each line in the file was padded with spaces to eight characters in length.
>>Today I tried in VB next code Dim HtmString As String Dim TextStream As System.IO.StreamReader Dim fso As Object, TextStream1 As Object If (My.Computer.FileSystem.FileExists(fpath)) Then TextStream = New System.IO.StreamReader(fpath, True) 'TextStream = System.IO.File.OpenText(fpath) HtmString = System.IO.File.ReadAllText(fpath) HtmString = TextStream.ReadToEnd() TextStream.Close() fso = CreateObject("Scripting.FileSystemObject") TextStream1 = fso.OpenTextFile(fpath) HtmString1 = TextStream1.ReadAll() End If HtmString and HtmString1 were different and HtmString1 has all spaces. Aleks Kleyn
The equivalent of the FileSystemObject code would be:
HtmlString = System.IO.ReadAllText(path, System.Text.Encoding.ASCII)
-- Göran Andersson _____http://www.guffa.com- Hide quoted text -
- Show quoted text -
i using visual basic.net. There is no difference where I use it: in
asp or desktop (the only difference that there is no global vars like
we use them in desktop).
Actually global variables doesn't exist at all in VB.NET. :) The
difference is that you can put variables in the form class in a windows
application, and as long as the form is shown the variables remain. In a
web application you have a page class instead, and that only lasts the
time that it takes to create one page, then it's gone.
Today's test showed this one more time.
Spaces do not disappear for reason of posting because all code runs on
the server.
I was talking about the spaces in my file that I was posting in the
newsgroup.
You probably mean System.IO.File.ReadAllText, because IO does not have
such method.
Yes, that's right.
Adding your encoding turned disappeared spaces to question mark, so
they are not really spaces. The question now is to find good encoding,
but this is no problem.
You can change the file extension to .bin and open it in Visual Studio.
That will show you a hex dump representation of the file, where you can
see exactly what it contains.
--
Göran Andersson
_____ http://www.guffa.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Leon Jollans |
last post by:
Hi.
I'm reading a 5 meg (or so) file from the response stream of a WebRequest,
and it's pitifully slow. I mean *really* slow, in the order of 15 minutes to
download. Now obviously I'm caching this...
|
by: Yechezkal Gutfreund |
last post by:
I have been using the following code (successfully) to read Xml formated
text packets from a TCP stream. The output from the server stream consists
of a sequence of well formed Xml documents...
|
by: Drew Yallop |
last post by:
I read an XML file with a stream reader in VB.Net. When I
look at the stream reader output in debug mode (by
passing cursor over the stream reader object)the format
is a perfect replica of the...
|
by: Scott |
last post by:
Hi guys,
If I try to call read(), readline(), readtoend() and
there is nothing to read (from a never ending loop for
example) the program seems to continue but it exits the
loop for no apparent...
|
by: Rob Meade |
last post by:
Hi all,
I'm having a few difficulties with the above, ie I cant find any good
examples anywhere of how to do what I want to do!
I have an xml file on my desktop which I want to read in.
...
|
by: .... |
last post by:
Hi
I have an existing function which has a stream object (inmsg.BodyPart.Data).
I'm trying to search and replace the stream object in the most efficient way
possible
This is my attempt below,...
|
by: John Kraft |
last post by:
Hello all,
I'm experiencing some, imo, strange behavior with the StreamReader
object I am using in the code below. Summary is that I am downloading
a file from a website and saving it to disk...
|
by: Martin Z |
last post by:
Hi,
I have an application that involves sending a lot of XML data to
various places. The problem is that once in a while, I just want the
XML document as a string (for example, sending to a...
|
by: Jack |
last post by:
Hi,
I want to read a string a chars from a stream, and put it into a
string.
At the moment, I'm creating a buffer of a fixed size, and reading the
stream of text into it. It works, but I have...
|
by: tomPee |
last post by:
Hi,
I've bumbed into a slight problem now, and I just don't seem to know how to fix it. What I want to do is the following:
Send over a socket:
1. Number of files to be send (not as an integer,...
|
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...
|
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...
|
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...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |