private void button39_Click(object sender, EventArgs e)
        {
            string l_text;
            string l_filename = "c:\\test.txt";
            string s = System.IO.File.ReadAllText("c:\\test.txt");
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "My Xbox Live Bio Creation";
            fdlg.InitialDirectory = @"c:\";
            fdlg.Filter = "All Files.* (*.*)|*.*|Text Files.txt (*.txt)|*.txt";
            fdlg.FilterIndex = 2;
            fdlg.RestoreDirectory = true;
            if (fdlg.ShowDialog() == DialogResult.OK)




            {
                l_filename = fdlg.FileName;

            }

            // System.IO.StreamReader file = new System.IO.StreamReader(l_filename);



            System.IO.StreamReader MyStreamReader = new System.IO.StringReader (l_filename, System.Text.Encoding.Unicode);
            
            int ch;

            ch = MyStreamReader.Read(); textBox1.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox2.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox3.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox4.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox5.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox6.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox7.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox8.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox9.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox10.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox11.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox12.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox13.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox14.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox15.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox16.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox17.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox18.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox19.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox20.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox21.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox22.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox23.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox24.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox25.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox26.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox27.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox28.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox29.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox30.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox31.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox32.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox33.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox34.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox35.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox36.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox37.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox38.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox39.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox40.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox41.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox42.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox43.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox44.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox45.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox46.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox47.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox48.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox49.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox50.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox51.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox52.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox53.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox54.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox55.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox56.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox57.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox58.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox59.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox60.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox61.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox62.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox63.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox64.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox65.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox66.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox67.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox68.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox69.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox70.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox71.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox72.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox73.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox74.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox75.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox76.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox77.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox78.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox79.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox80.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox81.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox82.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox83.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox84.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox85.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox86.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox87.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox88.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox89.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox90.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox91.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox92.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox93.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox94.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox95.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox96.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox97.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox98.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox99.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox100.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox101.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox102.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox103.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox104.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox105.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox106.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox107.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox108.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox109.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox110.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox111.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox112.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox113.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox114.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox115.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox116.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox117.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox118.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox119.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox120.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox121.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox122.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox123.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox124.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox125.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox126.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox127.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox128.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox129.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox130.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox131.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox132.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox133.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox134.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox135.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox136.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox137.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox138.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox139.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox140.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox141.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox142.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox143.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox144.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox145.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox146.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox147.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox148.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox149.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox150.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox151.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox152.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox153.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox154.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox155.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox156.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox157.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox158.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox159.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox160.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox161.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox162.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox163.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox164.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox165.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox166.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox167.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox168.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox169.Text = ch.ToString();
            ch = MyStreamReader.Read(); textBox170.Text = ch.ToString();


            MyStreamReader.Close();

I am trying to read each character from a file but each character is a unicode character. This code works and does what I want it to do apart from the one problem of it giving me the unicode value in a number. E.g.

If i want to read "Hello World!" it gives me This instead:

25928 27756 8303 28503 27762 8548

How do i make it so that if it says "Hello World!" in a text file it reads the file and inserts the 1st character (H) in to text box 1 and the 2nd character (E) in to text box 2 ?

I have finished my 2 month long project and I just need to fix this minor bug before releasing. Please help.

Recommended Answers

All 4 Replies

What would happen if you changed line 28 of your code into char ch;?

like

char ch;

??

I get 170 errors - "Error 2 Cannot implicitly convert type 'int' to 'char'. An explicit conversion exists (are you missing a cast?)"

when i change the lines with text boxes to char ch; at the start i get the error Error 1 A local variable named 'ch' is already defined in this scope

I have a file with unicode chars.
I need to extract each unicode character and assign to a variable e.g. textBox1.Text

The following two lines will read the first character in the file:

System.IO.StreamReader MyStreamReader = new System.IO.StreamReader(l_filename, System.Text.Encoding.Unicode);

int ch = MyStreamReader.Read(); textBox1.Text = ch.ToString();

The first character in the file is a single 's' however, when I inspect the contents of textBox1.Text, the value is 83.

The letter i am trying to put in textBox1.Text, is the letter 's' but all i get is the value 83

How do i convert the number 83 in to the letter s ?

Well that was just my point with the char answer I gave you.
The Read() method returns an integer which can be interpreted as an ASCII code. So instead of textBox1.Text = ch.ToString(); Which gives you the ASCII code converted to a string, you have to do something like this:

char c = (char)ch; //casting
            textBox1.Text = c.ToString(); //etc
            // or
            char d = Convert.ToChar(ch); //converting
            textBox1.Text = d.ToString(); //etc
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.