# Problem about read .txt file

**URL:** <https://www.ruby-forum.com/t/problem-about-read-txt-file/121271>\
**Category:** Ruby\
**Created:** [November 26, 2007, 11:10am UTC](https://www.ruby-forum.com/t/problem-about-read-txt-file/121271 "2007-11-26T11:10:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 26, 2007, 11:10am UTC](https://www.ruby-forum.com/t/problem-about-read-txt-file/121271/1 "2007-11-26T11:10:53Z")

</div>

I have read text by this code

```
  message = ""

  file = File.new(fileDirectory , "r")
    while line = file.gets
      message = message+line
    end
  file.close
  puts message
  @textbox1.set_value(message)

```

fileDirectory is a path of text file  
@textbox1 is textctrl that I want to show text in that file

and I have problem, it can only read text file with Encoding UTF-8, it  
can’t read from ANSI to show in textctrl (@textbox1) but

puts message

can show message normally with encode UTF-8 and ANSI

now I have problem how I can show text with encode ANSI in @textbox1??  
:’(

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 26, 2007, 11:30am UTC](https://www.ruby-forum.com/t/problem-about-read-txt-file/121271/2 "2007-11-26T11:30:53Z")

</div>

Pat K. wrote:

> ```
> @textbox1.set_value(message)
> 
> ```
> 
> now I have problem how I can show text with encode ANSI in @textbox1??

That sounds toolkit-specific. What GUI library are you using?

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 26, 2007, 11:37am UTC](https://www.ruby-forum.com/t/problem-about-read-txt-file/121271/3 "2007-11-26T11:37:34Z")

</div>

Alex Y. wrote:

> Pat K. wrote:
> 
> > ```
> > @textbox1.set_value(message)
> > 
> > ```
> > 
> > now I have problem how I can show text with encode ANSI in @textbox1??
> 
> That sounds toolkit-specific. What GUI library are you using?

I use wxruby 🙂

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 26, 2007, 3:40pm UTC](https://www.ruby-forum.com/t/problem-about-read-txt-file/121271/4 "2007-11-26T15:40:50Z")

</div>

On Nov 26, 3:10 am, Pat K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> @textbox1.set_value(message)
> 
> ```

How is the above different or better than:  
message = IO.read( fileDirectory )  
?

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 26, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/problem-about-read-txt-file/121271/5 "2007-11-26T17:05:18Z")

</div>

Dont know about wxruby but in ruby-gtk you can use Glib to convert  
charsets

But as someone else wrote before here, play around with iconv or similar  
to convert it before displaying on your GUI

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 26, 2007, 11:44am UTC](https://www.ruby-forum.com/t/problem-about-read-txt-file/121271/6 "2007-11-26T11:44:23Z")

</div>

Pat K. wrote:

> Alex Y. wrote:
> 
> > Pat K. wrote:
> > 
> > > ```
> > > @textbox1.set_value(message)
> > > 
> > > ```
> > > 
> > > now I have problem how I can show text with encode ANSI in @textbox1??  
> > > That sounds toolkit-specific. What GUI library are you using?
> 
> I use wxruby 🙂  
> I don’t know anything specific about WxRuby, but have you looked at  
> using iconv?
