Shop OBEX P1 Docs P2 Docs Learn Events
VB.NET 2010 again, trouble display letter " — Parallax Forums

VB.NET 2010 again, trouble display letter "

MoskogMoskog Posts: 554
edited 2013-04-08 11:00 in General Discussion
Hi!

Trouble here with VB.NET 2010..

I try to read a txt file into an array and one of the words include the Norwegian letter

Comments

  • MoskogMoskog Posts: 554
    edited 2013-04-05 13:30
    OK, so its ascii code 143 that also can be done by typing alt+143 but that doesnt solve the problem.
    I can type an "
  • MoskogMoskog Posts: 554
    edited 2013-04-05 13:58
    To make a better explanation of the problem, Screeshot left shows the .txt-file displayed in Notepad. Screenshot right shows the text displayed in a text box in VB.NET 2010 after being written to a String array and then displayed from there.
    screenshot1.jpg
    screenshot2.jpg
    268 x 211 - 22K
    213 x 172 - 10K
  • jmgjmg Posts: 15,173
    edited 2013-04-05 14:02
    Moskog wrote: »
    To make a better explanation of the problem, Screeshot left shows the .txt-file displayed in Notepad. Screenshot right shows the text displayed in a text box in VB.NET 2010 after being written to a String array and then displayed from there.

    Can you write to a file, and check that ?
    It may be reading fine, and just the viewing window has a different font, or handler.
  • MoskogMoskog Posts: 554
    edited 2013-04-05 14:09
    jmg wrote: »
    Can you write to a file, and check that ?
    It may be reading fine, and just the viewing window has a different font, or handler.

    Good point, I have no file-saving procedure yet but I can make one. But too late tonight, we will see tomorrow.
  • Mike GMike G Posts: 2,702
    edited 2013-04-05 15:50
    Moskog, you must always verify the current encoding and change it if needed.
     protected void WriteWithEncoding()
            {
                try
                {
                    using (StreamReader sr = new StreamReader("TestFile.txt"))
                    {
                        var encoding = Encoding.GetEncoding("iso-8859-1");
                        byte[] bytes = new byte[sr.BaseStream.Length];
                        sr.BaseStream.Read(bytes, 0, (int)sr.BaseStream.Length);
                        var line = encoding.GetString(bytes);
                        textBox1.Text = line;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-05 16:05
    Lots of experiments but this seems to work
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            RichTextBox1.Font = New Font("Arial", 18)
            Dim i As Integer
            For i = 32 To 255
                RichTextBox1.Text += Chr(i)
            Next
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            RichTextBox1.SaveFile("c:\new folder\demo.txt", RichTextBoxStreamType.PlainText)
        End Sub
    End Class
    
    1024 x 768 - 111K
  • MoskogMoskog Posts: 554
    edited 2013-04-08 11:00
    OK, problem solved, even though I really don't understand why.

    First I made a simple saving procedure by saving one word from a text box, including the special letter
Sign In or Register to comment.