|
-
Jul 29th, 2004, 09:20 AM
#1
Thread Starter
Junior Member
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.
-
Jul 29th, 2004, 09:26 AM
#2
Fanatic Member
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
-
Jul 29th, 2004, 10:01 AM
#3
Thread Starter
Junior Member
i tried a lot, using the encoding classes and reading byte per byte but i didnt manage to solve the problem.
-
Jul 29th, 2004, 10:41 AM
#4
Fanatic Member
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:
Dim strLine As String
FileOpen(1, strFilePath, OpenMode.Output)
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
-
Jul 30th, 2004, 02:37 AM
#5
Thread Starter
Junior Member
thanx, it works (after i altered your code a little). 
but still it is strange that writeline("adfšššššš") works but readline cannot read it
-
Jul 30th, 2004, 09:27 AM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|