473,396 Members | 2,108 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,396 software developers and data experts.

Streamreader problem

I have the following code in VB.net 2003

Dim s As String
Dim sr As StreamReader = New StreamReader("test.txt", New
UTF7Encoding)
s = sr.ReadLine
Debug.Write(s)

If the string read is 1+.03 it converts it to 1.3

If I remove the UTF7encoding option it does not.

Why should the encoding cause a text string to do arithmetic work? and
can I prevent it.

Thanks

Jack Russell
Oct 19 '06 #1
8 2076
I think it's in the UTF encoding.
The '+' may not be a valid charactor, so it ignores it.
Can you avoid UTF7? UTF8 seems to work fine.

--
Thiele Enterprises - The Power Is In Your Hands Now!
"Jack Russell" <ja***@norubbish.tpg.com.auwrote in message
news:OX****************@TK2MSFTNGP03.phx.gbl...
>I have the following code in VB.net 2003

Dim s As String
Dim sr As StreamReader = New StreamReader("test.txt", New
UTF7Encoding)
s = sr.ReadLine
Debug.Write(s)

If the string read is 1+.03 it converts it to 1.3

If I remove the UTF7encoding option it does not.

Why should the encoding cause a text string to do arithmetic work? and can
I prevent it.

Thanks

Jack Russell

Oct 20 '06 #2
Ryan S. Thiele wrote:
I think it's in the UTF encoding.
The '+' may not be a valid charactor, so it ignores it.
Can you avoid UTF7? UTF8 seems to work fine.
You are right, I just discovered that UTF7 regards + as an escape character.

I have files written by the old Fileopen, printline,fileclose method

I use streamreader to read these as it seems much faster than openfile,
lineinput.

It all works fine until I try to read files containing French such as

äüöéèà

The only way I can find to read these is with UTF7, everything else
ignores them.

Any ideas gratefully received.

Jack
Oct 20 '06 #3
Try Binary:

Dim sr As New BinaryReader(File.OpenRead("test.txt"))
Do While sr.PeekChar >= 0
Console.Write(Chr(sr.ReadByte))
Loop
sr.Close()

Notice I used chr code to convert bye to character.
--
Thiele Enterprises - The Power Is In Your Hands Now!
--
"Jack Russell" <ja***@norubbish.tpg.com.auwrote in message
news:OJ**************@TK2MSFTNGP06.phx.gbl...
Ryan S. Thiele wrote:
I think it's in the UTF encoding.
The '+' may not be a valid charactor, so it ignores it.
Can you avoid UTF7? UTF8 seems to work fine.
You are right, I just discovered that UTF7 regards + as an escape character.

I have files written by the old Fileopen, printline,fileclose method

I use streamreader to read these as it seems much faster than openfile,
lineinput.

It all works fine until I try to read files containing French such as

äüöéèà

The only way I can find to read these is with UTF7, everything else
ignores them.

Any ideas gratefully received.

Jack
Oct 20 '06 #4
Ryan S. Thiele wrote:
Try Binary:

Dim sr As New BinaryReader(File.OpenRead("test.txt"))
Do While sr.PeekChar >= 0
Console.Write(Chr(sr.ReadByte))
Loop
sr.Close()

Notice I used chr code to convert bye to character.

Well that works thanks but with the large files that I am reading it is
horrendously slow which is why I went to streamreader in the first
place!! Any other ideas?

Oct 20 '06 #5
Jack Russell wrote:
Ryan S. Thiele wrote:
Try Binary:

Dim sr As New BinaryReader(File.OpenRead("test.txt"))
Do While sr.PeekChar >= 0
Console.Write(Chr(sr.ReadByte))
Loop
sr.Close()

Notice I used chr code to convert bye to character.
Well that works thanks but with the large files that I am reading it is
horrendously slow which is why I went to streamreader in the first
place!! Any other ideas?
Have you tried Encoding.Default instead of UTF7? What encoding was
used to write the file?

Oct 20 '06 #6
Are you editing the text? Use a richtext box...

Me.RichTextBox1.LoadFile("Text.exe", RichTextBoxStreamType.PlainText)
--
Thiele Enterprises - The Power Is In Your Hands Now!

--
"Jack Russell" <ja***@norubbish.tpg.com.auwrote in message
news:ed**************@TK2MSFTNGP05.phx.gbl...
Ryan S. Thiele wrote:
Try Binary:

Dim sr As New BinaryReader(File.OpenRead("test.txt"))
Do While sr.PeekChar >= 0
Console.Write(Chr(sr.ReadByte))
Loop
sr.Close()

Notice I used chr code to convert bye to character.

Well that works thanks but with the large files that I am reading it is
horrendously slow which is why I went to streamreader in the first
place!! Any other ideas?
Oct 20 '06 #7
Chris Dunaway wrote:
Jack Russell wrote:
>>Ryan S. Thiele wrote:

>>>Try Binary:

Dim sr As New BinaryReader(File.OpenRead("test.txt"))
Do While sr.PeekChar >= 0
Console.Write(Chr(sr.ReadByte))
Loop
sr.Close()

Notice I used chr code to convert bye to character.


Well that works thanks but with the large files that I am reading it is
horrendously slow which is why I went to streamreader in the first
place!! Any other ideas?


Have you tried Encoding.Default instead of UTF7? What encoding was
used to write the file?
I do not know what encoding was used, it was written using the "old" VB
method of file open, printline, file close. I have not been able to find
out what encoding that uses. Just to recap my problem the file can
contain foregin characters such as äüöéèà. If I do not specify any
encoding when I open the streamreader these get lost. If I specify UTF7
they are found but UTF7 treats + as an escape character. I will try
default but ...
Oct 20 '06 #8
Jack Russell wrote:
Chris Dunaway wrote:
>Have you tried Encoding.Default instead of UTF7? What encoding was
used to write the file?
I do not know what encoding was used, it was written using the "old"
VB method of file open, printline, file close. I have not been able
to find out what encoding that uses.
I suspect you'll find the bits you need in the help at the
System.Text.ASCIIEncoding section, and something to do with Windows-1252 or
ISO 8859-1.

If you look at your file with a hex editor, do the accented characters
correspond to the ones in this table:-
http://en.wikipedia.org/wiki/Windows-1252

?

Also see http://en.wikipedia.org/wiki/ISO_8859-1.

HTH

Andrew
Oct 23 '06 #9

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

Similar topics

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...
3
by: redneon | last post by:
I have a program which is constantly reading from a stream and what I'm wanting to do is, if the stream hasn't sent anything after a certain amount of time then do something. I've tried doing this...
4
by: Astronomically Confused | last post by:
using System; using System.Collections; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; class HttpProcessor { private Socket s;
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: Mika M | last post by:
Hello! I'm reading text file line by line using the StreamReader like code below shows. Reading is working fine, but if readed line contains Scandinavian letters like äÄöÖ then those letters are...
2
by: James Wong | last post by:
Dear all, I'm using StreamReader to read a text file containing BIG-5 data and found that no matter which encoding method in StreamReader's construction parameter, the BIG-5 contents become...
11
by: LucaJonny | last post by:
Hi, I've got a problem using StreamReader in VB.NET. I try to read a txt file that contains extended characters and theese are removed from the line that is being read. I've read a lot of...
4
by: Hexman | last post by:
Code below ---- I've asked a similar question on this forum earlier. This is a slightly different situation. Previous Question ---- I'm trying to save some specific web pages to disk as...
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 =...
3
by: =?Utf-8?B?Qm9zc2ll?= | last post by:
Hi All, I am having a little trouble with a StreamReader. I am currently reading a pipe delimited file with around 1.8 million records (total size 150MB) and, based on a flag, insert update or...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.