Can not read special characters from text file.

How can I read "" from a text file?

Page 1 of 1

4 Replies - 15364 Views - Last Post: 19 November 2008 - 06:17 AM Rate Topic: -----

#1 jens  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 430
  • Joined: 09-May 08

Can not read special characters from text file.

Post icon  Posted 18 November 2008 - 03:01 PM

Hello!

I am trying to read a file that consists of rows of text. All works well except that special characters are not read correctly. What happens is that the variable "input" gets the first line correctly and all characters from the second except "" correctly. The special characters just disappear. I've been trying to use "unicode" while declaring the objReader but it didn't work. Now I'm out of ideas. Help please?

The code I'm using (VB2008Express)
   Private Function fileToStrings2(ByVal filNamn As String) As boolean
        Dim input As String
        Dim objReader As New System.IO.StreamReader(filNamn)

        Do While objReader.Peek() <> -1
            input = objReader.ReadLine()  ' <- Offending line of code 
            msgbox(input)
        Loop

        return True
   End Function



The rows I'm trying to read

Quote

#2008-11-07 10:55:41#,"First line of text with no special characters"
#2008-11-07 10:57:24#,"Second line with () special characters"

Regards
/Jens

PS: I did take some functionality out of the code to clarify and get my point across.

This post has been edited by jens: 18 November 2008 - 03:07 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Can not read special characters from text file.

#2 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: Can not read special characters from text file.

Posted 18 November 2008 - 08:58 PM

Try UTF7 System.Text.Encoding.UTF7... hell try them all thats my lazy way of figuring it out...
Was This Post Helpful? 1
  • +
  • -

#3 jens  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 430
  • Joined: 09-May 08

Re: Can not read special characters from text file.

Posted 19 November 2008 - 12:40 AM

Hi!

Thanks. You write "try them all"... Them all?? How can I find out what "them all" is? :) I guess there is a listing somwhere. And, just in case, it is where I wrote codingStuffGoesHere that I put the coding information, no?

 Dim objReader As New System.IO.StreamReader(filNamn, codingStuffGoesHere?)  


Thanks
/Jens

PS: How do you make the little box that surrounds System.Text.Encoding.UTF7?
Was This Post Helpful? 1

#7 jens  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 430
  • Joined: 09-May 08

Re: Can not read special characters from text file.

Posted 19 November 2008 - 02:51 AM

A little later...: Hello again!

Thank you for your help, I followed you suggestion and found that this
Using inputFile As IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(filNamn, System.Text.Encoding.Default)

...did the trick.

Makes me wonder though, how come .Encoding.Default makes it work? Isn't ".Default" the default? :crazy:

Regards
/Jens
Was This Post Helpful? 1

#11 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: Can not read special characters from text file.

Posted 19 November 2008 - 06:17 AM

Well Default is the OS's default code page, which I don't recommend to use as your code might not work on another machine with the same input files. I would keep changing them till you find the one that does work so you don't run into the problems if you tend to run the code else where.

You can still specify the encoding with the streamreader Dim objReader As New System.IO.StreamReader(filNamn, System.Text.Encoding.Default) , just as you guessed.

The tags are for inline code and they are IL and /IL. If you click on the Show All BB Code Help link under the Clickable Smilies you can see all the different tags.
Was This Post Helpful? 1

Page 1 of 1