• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 758
  • Last Modified:

Reading special characters from CSV with Visual Basic .NET

I created a csv file (using excel 2007).  I need to be able to save text from different languages in this file, and I can.  I paste phrases in the csv, save it and when I open the file, the phrases show up exactly as I pasted them in.  An example of one such phrase is "DisposiciĆ³n".  The problem is that I need to process this csv with a visual basic program (using Visual Studio 2005).  When I read the lines of the csv into VB, the accented character shows up as a "square"...

Here's a snippet of my code:
        Dim fileLine As String

        ' open the file...
        Using streamReader As New IO.StreamReader(txtFileName.Text)

            fileLine = streamReader.ReadLine

"fileLine" contains:  "DisposiciĆ½n"

Can someone tell me how I can read this csv and get the special characters?  I've tried creating my StreamReader like so:
Using streamReader As New IO.StreamReader(txtFileName.Text, Encoding.Unicode)

and this is worse...

Any help would be greatly appreciated!
0
ablesa
Asked:
ablesa
  • 3
  • 2
1 Solution
 
VBRocksCommented:
Try this:

    Using streamReader As New IO.StreamReader(txtFileName.Text, Encoding.GetEncoding(0))


0
 
VBRocksCommented:
You can also use 1252, like this:

    Using streamReader As New IO.StreamReader(txtFileName.Text, Encoding.GetEncoding(1252))

0
 
ablesaAuthor Commented:
the first one works with the spanish, but as I was testing further, I see that I now have a problem with my csv file.  I copied and pasted some chinese characters into my csv and saved it (using Arial).  When I pasted the text into the file, it was displaying properly, but when I save and re-open the file, it displays "????" where the chinese characters should have been.  Any ideas there?

Thanks so much for your help!
0
 
VBRocksCommented:
I'm not sure how to handle that, because they use different encodings.  You may need to come up
with a way to tag each section with the appropriate codepage (ex. 1252 for Western-European), and
then extract the tag and change encoding before reading it...

Sorry.


0
 
ablesaAuthor Commented:
no  problem.  thanks for your help.  You got me past the major hurdle!  
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now