Reading from file errors...

Hi everybody..

This is the problem I have:

I have a .txt archive which contains lines for configuring labels, buttons, and other controls of my form. This archive is written in spanish and some letters have an accent. I can read wit no problem the line, but when I assign the value I get (string type) to the text property of the control, the accent letters did not appear at all. Now I tried configuring my regional settings, before I had English (USA) and I tried changing it to Spanish (Mexico) but the accent letters now appear as an " ".

In my VB6 app, this was no problem. Checking my .txt is saved with an ANSI encoding. So I guess changing the encoding to something else will work, but how to know whats the best type Or which is the one it will work

Thanks!




Answer this question

Reading from file errors...

  • Andy_Paul

    Sup everyone... my problem is resolved. I used UTF-8 encoding when declaring my streamreader and saved my file to UTF-8 encoding too and that was all =). Thanks everyone for guiding me on my problem. Just one extra question, what the difference between encodings I mean I guess some use som characters or something like that. But don't know for sure what the difference between them. Can anyone tell me

    Thanks.
    JP



  • Mitch0820

    Sup Peter...

    I know there are other ways to handle it and load the info.. but can't change the way the project was defined =S.. thats wack... I know.. so thats why I need to get it working properly the way it is right now.



  • Streetsmart

    saving my .txt with unicode will help me display the text correctly or do I have to change encoding in my code also

  • Godwin Lang

    1. save text file in Unicode
    2. Dim textr As New StreamReader(oFS, System.Text.Encoding.Unicode)


    Does it help


  • LICNYC

    ASCII encoding was used in DOS, 1 byte per character (256 different chars)
    ANSI encoding was used in Windows, 1 byte per char
    Unicode encoding - modern encoding, 2 bytes per char (65536 different chars)

    When using Unicode - you can store all characters from different languages in the same encoding.

    When using ANSI/ASCII encodings same numbers can represent different letters, all depend on code page.


  • WarrenB

    Sup Sergey...

    Right now what I do is that I open the file (the .txt is saved as ANSI), declare a streamreader with no encoding defined all the lines in my file are defined as
    an ID = Text... so when I read a line I get the index of the "=" and I get the right part and pass the value to my function output. And then in my form, I assign the value to the text property of my control in the form.. Heres part of the code...

    Dim textr As New StreamReader(oFS)

    Try

    While textr.Peek <> -1

    sTextLine = textr.ReadLine()

    iPos = sTextLine.Length - 1

    If sTextLine.IndexOf("=") > 0 Then

    If sTextLine.Substring(0, sTextLine.IndexOf("=")).ToUpper = parParameterName Then

    temp = sTextLine.Substring(sTextLine.IndexOf("=") + 1, (sTextLine.Length - 1) - sTextLine.IndexOf("="))

    GetParameter = temp

    Exit While

    End If

    End If

    End While

    .... return value

    I tried reading with default system encoding but the accent letters are omitted.
    Thanks S!



  • dcaton2

    Thanks SG... I have a better idea of different encoding. =)



  • Mardo

    Hi!

    ANSI is bad for multilanguage text, use Unicode instead.


    appears when letter can't be shown in current encoding.


  • mgaur

    Why not store that information in a resource file and load the appropariate text via My

  • Rajesh_B

    How you load text You must save & load in Unicode. Post this code here.


  • Reading from file errors...