Hi. I'm going around and around with an issue that I can't seem to get
around. I have a function I wrote that uses a StreamReader to read a
text file into a string variable. It's been working well for some time,
but we've discovered it doesn't work with foreign language files. We
have a text file in French, and the reader strips out characters like é.
That's no good for us. I'm thinking if I could make the reader use
Unicode instead of UTF-8 it might help, but I can;t seem to get that to
work.
My existing code is this:
Public Shared Function File2String(ByVal strFile)
'Open a file for reading
Dim strFilename As String = strFile
'Get a StreamReader class that can be used to read the file
Dim oReader As System.IO.StreamReader 'System.IO.StreamReader
'oReader.CurrentEncoding = System.IO.enc
Try
oReader = System.IO.File.OpenText(strFilename)
Catch ex As Exception
Return Nothing
End Try
'Dim test As String = objStreamReader.CurrentEncoding
Dim str As String = oReader.ReadToEnd.ToString
oReader.Close()
Return str
End Function
--------------
Some examples I've found specify the stream and encoding when the reader
is declared. So I've been trying to do that by moving the declaration to
inside the try/catch like this:
Try
Dim oReader As New
StreamReader(System.IO.File.OpenText(strFilename), Encoding.Unicode,
True, 1024)
Catch ex As Exception
Return Nothing
End Try
But Intellisense is balking at my definition (and many variations of it)
saying: Overload resolution failed because no accessible "New" can be
called with these arguments:...
I think I'm close but I can't seem to get it. Anyone got any tips or
examples that might work for me? I don;t even know if this is the right
way to solve this but I don't know of any other approaches.
Much thanks in advance for anything useful!
Matt 3 2116
Matt,
You will have no effect when your computer does not support the right
codeset. Countries in America, Australia (continents), Parts of Africa and
Western Europe share the same code set. (1252)
(It can be that the file is created with another code set than you would
suppose and than you are again in trouble).
However that is the first you have to check on your computer in the config.
With information in this link you should find your problem I think. http://www.microsoft.com/globaldev/r...ocversion.mspx http://www.geocities.com/Athens/Acad.../fontset.htm#b
I hope this helps?
Cor
Cor Ligthert wrote: Matt,
You will have no effect when your computer does not support the right codeset. Countries in America, Australia (continents), Parts of Africa and Western Europe share the same code set. (1252)
(It can be that the file is created with another code set than you would suppose and than you are again in trouble).
However that is the first you have to check on your computer in the config.
With information in this link you should find your problem I think.
http://www.microsoft.com/globaldev/r...ocversion.mspx
http://www.geocities.com/Athens/Acad.../fontset.htm#b
I hope this helps?
Cor
Thanks for the reply!
Maybe I have the problem mis-diagnosed, because if I open the file in
Notepad, I see the characters. It's when I read the file into a vb.net
TextReader that I lose characters like é (it's an e with an accent).
Any ideas on clearing that up? My computer seems to be able to support
them, it's just when I read the files into my application things go wrong.
Matt
Matt, Thanks for the reply! Maybe I have the problem mis-diagnosed, because if I open the file in Notepad, I see the characters. It's when I read the file into a vb.net TextReader that I lose characters like é (it's an e with an accent).
Than why are you than encode them and not just read them using
rd.readtoend http://msdn.microsoft.com/library/de...ToEndTopic.asp
I hope this helps,
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: PAN |
last post by:
I need some guidance here
I've written this HTML code using the Windows Notebook:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EL">
<html>
<head>
<title>This is a Greek language title ->...
|
by: Jay Douglas |
last post by:
I am trying to do an HTTP POST to a webpage from a DLL. The webpage is
easily called, and a response is given. However, the web page is not
receiving the POSTed variables. None of them. ...
|
by: fitsch |
last post by:
Hi,
I am trying to write a generic RSS/Atom/OPML feed client. The problem
is, that those xml feeds may have different encodings:
- <?xml version="1.0" encoding="ISO-8859-1" ?>...
- <?xml...
|
by: Marc Jennings |
last post by:
Hi there,
Can anyone point out any really obvious flaws in the methodology below
to determine the likely encoding of a file, please? I know the number
of types of encoding is small, but that is...
|
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...
|
by: Zhiv Kurilka |
last post by:
Hi,
I have a text file with following content:
"((^)|(.* +))§§§§§§§§"
if I read it with:
k=System.IO.StreamReader( "file.txt",System.Text.Encoding.ASCII);
k.readtotheend()
|
by: Christopher Brandsdal |
last post by:
Hi!
I have found a script to lookup domain names, but it is written in C#. I
want so bad to translate this to VB! Can anyone help me? I have tried
myself. The script seems to run fine, but I...
|
by: WH |
last post by:
Hi,
I use a Streamreader in VB2005 to read text files I made before in NotePad,
but it can't read characters like "é" or "ç". They are omitted, or replaced
by other characters. I tried different...
|
by: billsahiker |
last post by:
if an xml file specifies an encoding, e.g., utf16, do xml browsers and
xml editors read and verify each character in the file to make sure it
is utf16? and throw an error if it is not, or. do they...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |