Results 1 to 5 of 5

Thread: [RESOLVED] reading unicode text from a file? Swedish seems to be dropped when read into a string

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    665

    Resolved [RESOLVED] reading unicode text from a file? Swedish seems to be dropped when read into a string

    I can see the unicode chars before I post the thread mår. The a for example.

    Code:
    00170     2200061   4500500004000000520005200040901001600092  aHur mår du?Hur är läget?FörlåtHejdå  aHur är läget?Hur mår du?FörlåtHur mår du?Förlåt  a85843322572
    I gather a string from a file like this
    Code:
     Dim content As String = IO.File.ReadAllText(FilenameToBreak)
    but immediate window does not show it, except as odd looking black question marks
    I am hoping the website here does not destroy it and you can see what it does.

    Anyhow how can I read this properly into a string? Bothe Notepad and Notepad++ read it fine and show the right chars.
    Code:
    "00170     2200061   4500500004000000520005200040901001600092" & ChrW(30) & "  " & ChrW(31) & "aHur m?r du?Hur ?r l?get?F?rl?tHejd?" & ChrW(30) & "  " & ChrW(31) & "aHur ?r l?get?Hur m?r du?F?rl?tHur m?r du?F?rl?t" & ChrW(30) & "  " & ChrW(31) & "a85843322572" & ChrW(30) & ChrW(29)

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    665

    Re: reading unicode text from a file? Swedish seems to be dropped when read into a st

    No unicode read here either
    Code:
            Dim fileReader As System.IO.StreamReader
            fileReader = My.Computer.FileSystem.OpenTextFileReader(FilenameToBreak)
            Dim stringReader As String
            stringReader = fileReader.ReadToEnd()

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    665

    Re: reading unicode text from a file? Swedish seems to be dropped when read into a st

    This works but I bet only for code page 1252 languages.
    Bad if your text file has say, English, Swedish, Chinese chars?
    How is this done?
    You can't assume a file is Swedish or Indonesian or Arabic or a mix of languages.
    How can you assume anything about the text in a text file?

    Code:
     Dim content As String = IO.File.ReadAllText(FilenameToBreak, System.Text.Encoding.GetEncoding(1252))
    Code:
    " ChrW(31) & "aHur mår du?Hur är läget?FörlåtHejdå" & ChrW(30) & "  " & ChrW(31) & "aHur är läget?Hur mår du?FörlåtHur mår du?Förlåt" & ChrW(30) & "  " & ChrW(31) & "a85843322572" & ChrW(30) & ChrW(29)

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    665

    Re: reading unicode text from a file? Swedish seems to be dropped when read into a st

    Maybe I got it with this?
    This looks good, so willl mark it resolved.

    Please comment!
    I have noticed China chars dont work here, so here is a screen shot



    Code:
            Dim fileReader As System.IO.StreamReader
            fileReader = My.Computer.FileSystem.OpenTextFileReader(FilenameToBreak, System.Text.Encoding.UTF8)
            Dim stringReader As String
            stringReader = fileReader.ReadToEnd()
    Code:
    ?stringreader
    """aHur mår du?Hur är läget?FörlåtHejdå  ??3????????"
    Attached Images Attached Images  

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    665

    Re: [RESOLVED] reading unicode text from a file? Swedish seems to be dropped when rea

    Also adding this single line seems to be working now.
    Who knows if it will keep working

    Dim content As String = IO.File.ReadAllText(FilenameToBreak, System.Text.Encoding.UTF8)

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