473,385 Members | 1,973 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,385 software developers and data experts.

StreamReader problem with Scandinavian letters (äÄöÖ)

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 simply cut off ! Why ??? For
example my lastname Mähönen will be Mhnen. How should I change code to get
all letters as is of the file?

Dim strLine as String
Dim sr As StreamReader = New StreamReader(strFilePath)
Do While ...
strLine = sr.ReadLine()
'...
Loop
sr.Close()

Thank you in advance!

Mika from Finland
Nov 20 '05 #1
3 3175
"Mika M" <m i k a.m a h o n e n@kolumbus.fi> schrieb
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 simply cut off
! Why ??? For example my lastname Mähönen will be Mhnen. How should I
change code to get all letters as is of the file?

Dim strLine as String
Dim sr As StreamReader = New StreamReader(strFilePath)
Do While ...
strLine = sr.ReadLine()
'...
Loop
sr.Close()


Which encoding has been used to write the file? I guess it's ANSI. You can
pass the Encoding to the Streamreader:

Dim sr As StreamReader = New StreamReader( _
strFilePath, System.Text.Encoding.Default _
)

If you need a different encoding, have also a look at the other members of
the Encoding class. You can also create a new one using it's GetEncoding
function.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #2
* "Mika M" <m i k a.m a h o n e n@kolumbus.fi> scripsit:
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 simply cut off ! Why ??? For
example my lastname Mähönen will be Mhnen. How should I change code to get
all letters as is of the file?

Dim strLine as String
Dim sr As StreamReader = New StreamReader(strFilePath)


Replace the line above with
'... = New StreamReader(strFilePath, Encoding.Default)'.

Don't forget to import the namespace 'System.Text'.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Mika,
Dim sr As StreamReader = New StreamReader(strFilePath)
You need to give the proper System.Text.Encoding object to the StreamReader
constructor, for the encoding that the file is in.

The default encoding object is Encoding.UTF8, I suspect you want
Encoding.Default, which is the encoding for your system's current ANSI code
page.

Something like:

Imports System.Text
Dim sr As StreamReader = New StreamReader(strFilePath, Encoding.Default)
Hope this helps
Jay

"Mika M" <m i k a.m a h o n e n@kolumbus.fi> wrote in message
news:bn**********@phys-news1.kolumbus.fi... 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 simply cut off ! Why ??? For
example my lastname Mähönen will be Mhnen. How should I change code to get
all letters as is of the file?

Dim strLine as String
Dim sr As StreamReader = New StreamReader(strFilePath)
Do While ...
strLine = sr.ReadLine()
'...
Loop
sr.Close()

Thank you in advance!

Mika from Finland

Nov 20 '05 #4

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: ...
9
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using 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...
1
by: Rob T | last post by:
Hi, I have a simple little program that I'm going to use to access our SMTP server. The below code works perfectly fine, but my question is if I were to try to execute the last line...
0
by: Sebitti | last post by:
I have a web service that is called from vb6. If I send parameters from vb6 to webservice that has scandinavian marks the marks are changed into ?? characters. The returnvalue from the web service...
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: 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 =...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
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 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.