473,473 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

to read a textfile regarding his format

A textfile can have different formats like ANSI,UTF8, Unicode ...
Using streamreader for a textfile can have different results for chars like
é,à,è....depending of the fileformat.
To solve this problem I have in the code analysed the chars in the beginning
of the textfile, named the BOM to see the system.text.encoding for using
this information in the streamreader.
But my question is :
Is there a way that vb.net can do this automatically?
Thanks for any response
May 13 '06 #1
8 1989
with the boolean in the constructor of the streamreader you can set it to
automaticly detect the Byte Order Mark

regards

Michel Posseth

"andreas" <an*****@pandora.be> schreef in bericht
news:6Z**********************@phobos.telenet-ops.be...
A textfile can have different formats like ANSI,UTF8, Unicode ...
Using streamreader for a textfile can have different results for chars
like
é,à,è....depending of the fileformat.
To solve this problem I have in the code analysed the chars in the
beginning
of the textfile, named the BOM to see the system.text.encoding for using
this information in the streamreader.
But my question is :
Is there a way that vb.net can do this automatically?
Thanks for any response

May 14 '06 #2
I have placed the code
dim sr as new streamreader(filename,true)
but the sr didn't recognise a ANSI file made with notepad
the chars é,à,è.... are disapeared
I missed something?
"Michel Posseth [MCP]" <MS**@posseth.com> wrote in message
news:#v**************@TK2MSFTNGP05.phx.gbl...
with the boolean in the constructor of the streamreader you can set it to
automaticly detect the Byte Order Mark

regards

Michel Posseth

"andreas" <an*****@pandora.be> schreef in bericht
news:6Z**********************@phobos.telenet-ops.be...
A textfile can have different formats like ANSI,UTF8, Unicode ...
Using streamreader for a textfile can have different results for chars
like
é,à,è....depending of the fileformat.
To solve this problem I have in the code analysed the chars in the
beginning
of the textfile, named the BOM to see the system.text.encoding for using
this information in the streamreader.
But my question is :
Is there a way that vb.net can do this automatically?
Thanks for any response


May 14 '06 #3
try this, maybe this will help.

Dim myStreamWriter As New StreamWriter(FileName, False,
System.Text.Encoding.Default)

May 15 '06 #4
I don't think that it helps because a system.text.encoding.default gives a
ANSI encoding and mentioning nothing gives UTF8

<ar********@gmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
try this, maybe this will help.

Dim myStreamWriter As New StreamWriter(FileName, False,
System.Text.Encoding.Default)

May 15 '06 #5
I copied and paste this char(é,à,è) in the notepad and
save it as UTF8 encoding.
then i tried the code below and i have no problem.
dim sr as new streamreader(filename,true)
and
Dim myStreamReader As New System.IO.StreamReader(objFile.FullName,
System.Text.Encoding.UTF8, False)

please check your textfile.

May 15 '06 #6
<ar********@gmail.com> schrieb:
I copied and paste this char(é,à,è) in the notepad and
save it as UTF8 encoding.
then i tried the code below and i have no problem.
dim sr as new streamreader(filename,true)
and
Dim myStreamReader As New System.IO.StreamReader(objFile.FullName,
System.Text.Encoding.UTF8, False)

Both will work if the file is stored using UTF-8. By specifying no encoding
in the constructor, UTF-8 is used.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 15 '06 #7
Thanks everyone but this is not what I want.
I know what is written.
I want to read the textfile without knowing what the format is
(ANSI,UTF8,Unicode...)
Now, I can do that only by code by looking at the first bytes in the file.
My question is , is there a method that the code read automaticly the right
format?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:#B**************@TK2MSFTNGP03.phx.gbl...
<ar********@gmail.com> schrieb:
I copied and paste this char(é,à,è) in the notepad and
save it as UTF8 encoding.
then i tried the code below and i have no problem.
dim sr as new streamreader(filename,true)
and
Dim myStreamReader As New System.IO.StreamReader(objFile.FullName,
System.Text.Encoding.UTF8, False)

Both will work if the file is stored using UTF-8. By specifying no

encoding in the constructor, UTF-8 is used.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 15 '06 #8
"andreas" <an*****@pandora.be> schrieb:
Thanks everyone but this is not what I want.
I know what is written.
I want to read the textfile without knowing what the format is
(ANSI,UTF8,Unicode...)
Now, I can do that only by code by looking at the first bytes in the file.
My question is , is there a method that the code read automaticly the
right
format?


AFAIK no.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 15 '06 #9

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

Similar topics

7
by: [ F e r n a n d o L o p e s ] | last post by:
Hello ALL, I need to read data from a .txt file and save this data in a sql server database table. The .txt file format like this: -----------------------------------------------------------...
2
by: Tim | last post by:
Greetings, I need to read the contents of a textfile to memory and then write these contents to another location. I was thinking of reading this data into a datareader, but I don't see...
2
by: Sam | last post by:
Hi guys If I have to read/write a text file which has the following format, what would be the best way to read it? Should I readline method of the streamreader to a string variable and parse it...
9
by: Justme | last post by:
Novice programmer needs help with using fgets to read and ignore the first two lines of a file. I've gone thru the previous posting regarding fgets, but none of them seems to help my situation. I...
3
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a...
2
by: RaviRajhulk | last post by:
I am trying to read folder and subfolder and print their name into a text file.I am able to read the folder and its content and write it to the textfile but I am not able to read the content of the...
3
by: Jone | last post by:
Hello, I have tried to convert a Mac text file to Windows using code below. Encoding Win = Encoding.GetEncoding("Windows-1252"); Encoding Mac = Encoding.GetEncoding("macintosh"); byte...
6
by: Per Juul Larsen | last post by:
Hi. My Textfile looks like this Variable 1 Variable 2 Variable 3 Variable 4 On opening the application it will read the textfile, and assign each line of variable to at textfield in VB and...
3
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I am trying to loop a Textfile. This Textfile is located on a shared drive and it is used by another process. When I try to read it I get an exeption: The process cannot access the...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.