Results 1 to 6 of 6

Thread: reading special characters from a text file RESOLVED

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    27

    reading special characters from a text file RESOLVED

    I have the following code which will read "normal" characters from any textfile just fine:

    Code:
               
               Dim oRead As StreamReader
                Dim oFile As File
                Dim currentLine As System.String
                oRead = oFile.OpenText(Global.directory)
    
                While oRead.Peek <> -1
                    currentLine = oRead.ReadLine()
                    If Not File.Exists(Global.homedirectory + "\teste.txt") Then
                        Dim oWrite As New System.IO.StreamWriter(Global.homedirectory + "\teste.txt")
                        oWrite.WriteLine(currentLine)
                        oWrite.Close()
                    End If
                    MessageBox.Show(currentLine)
    
                End While
                oRead.Close()
    But my problem is, that it does not read special characters.

    My textfile contains: "ašššb" . But Readline() reads only "ab".

    I thought UTF-8 supports foreign characters? But apparently, it does not.

    Any help is appreciated.

    Thanx,
    Usul
    Last edited by Usul; Jul 30th, 2004 at 04:44 AM.

  2. #2
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    i don't know much about this sort of thing, but have you tried using unicode instead? if you can... i'm not sure

    just a thought, unicode might handle it

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    27
    i tried a lot, using the encoding classes and reading byte per byte but i didnt manage to solve the problem.

  4. #4
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    it may have something to do with StreamReader or StreamWriter.

    I would suggest using the other way... sorry, I don't know what you call it. I'll give you an example of what you need.

    Use this to open the file you want to read
    VB Code:
    1. Dim strLine As String
    2. FileOpen(1, strFilePath, OpenMode.Output)
    3. strLine = LineInput(1)
    That should read the line into the string strLine
    Hopefully that will include the characters that are missing.
    If you're trying to write strLine into a different file, and it doesnt work with StreamWriter, i suggest doing the same method but
    PrintLine(1, strLine) instead, replacing 1 with the filenumber you got open.
    Hope that helps, ask any questions if you're not sure

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    27
    thanx, it works (after i altered your code a little).

    but still it is strange that writeline("adfšššššš") works but readline cannot read it

  6. #6
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    hmm yeah, strange... glad it works tho

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width