# STC encoding

**URL:** <https://www.ruby-forum.com/t/stc-encoding/226066>\
**Category:** wxRuby\
**Created:** [May 28, 2010, 12:58pm UTC](https://www.ruby-forum.com/t/stc-encoding/226066 "2010-05-28T12:58:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [May 28, 2010, 12:58pm UTC](https://www.ruby-forum.com/t/stc-encoding/226066/1 "2010-05-28T12:58:35Z")

</div>

i’d like to use StyledTextCtrl in my aplication, to edit Watir tests.

But i have a great problem with encoding, i work on windows xp  
(unfortunately) and all tests i have had been written in utf-8, in  
NetBeans.

When i open a file in my own editor i see characters like “uÄ¹Ä½y” instead  
of polish characters.  
When i type in my own editor i can use polish characters, and they are  
displayed good.  
When i edit a file and save it, i see “ï¿½ï¿½” instead of polish characters.

I have tried a lot of combinations with:

@sci.style\_set\_character\_set(STC\_STYLE\_DEFAULT, 0)  
@sci.set\_code\_page(65001)  
@sci.style\_set\_font\_encoding(STC\_STYLE\_DEFAULT, FONTENCODING\_UTF8)  
Font.set\_default\_encoding(FONTENCODING\_UTF8)  
but it didnt help

if i use File.new to create a file and File.puts contents inside of it,  
and load this script into my editor i see wrongly displayed polish  
characters, but when i run a test i get correct characters in output, so  
the problem is when i write sth and save it.

–code for load and save–

evt\_button(@button\_edit\_bottom.get\_id()){  
|event|  
file\_to\_edit = @listbox\_added.get\_selections()  
file\_to\_edit = file\_to\_edit[0]  
file\_to\_edit = $tests[file\_to\_edit]  
@sci.load\_file("#{file\_to\_edit}")  
@input\_edit\_save.set\_value("#{file\_to\_edit}")  
}  
evt\_button(@button\_edit\_save.get\_id()){  
|event|  
edited\_file\_to\_save = @input\_edit\_save.get\_line\_text(0)  
if edited\_file\_to\_save != “”  
f = File.new("#{edited\_file\_to\_save}",“w”) if  
File.exists?("#{edited\_file\_to\_save}") == false  
@sci.save\_file("#{edited\_file\_to\_save}")  
file\_to\_reedit = @input\_edit\_save.get\_line\_text(0)  
@sci.load\_file("#{file\_to\_reedit}")  
@input\_edit\_save.set\_value("#{file\_to\_reedit}")  
else  
@mdialog\_input\_edit\_save = MessageDialog.new(@my\_panel,  
“Name the file please”, “Oops!”, OK, DEFAULT\_POSITION)  
@mdialog\_input\_edit\_save.show\_modal()  
end  
}

---

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [May 28, 2010, 3:14pm UTC](https://www.ruby-forum.com/t/stc-encoding/226066/2 "2010-05-28T15:14:34Z")

</div>

the problem seams to be related to load\_file and save\_file.

```
        f = File.new("#{edited_file_to_save}","w+")
        f.each do |line|
          line.delete
        end
        contents_to_save = @sci.get_text#tu
        f.puts contents_to_save
        f.close

```

works for me

---

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [June 6, 2010, 1:44am UTC](https://www.ruby-forum.com/t/stc-encoding/226066/3 "2010-06-06T01:44:27Z")

</div>

AFAIK

Opening in ‘w’ mode truncates existing file to zero length, or create  
new file. ‘w+’ is same but allow to read the file too. so, in both cases  
file is clear upon opening.

line.delete does nothing there. f.each yelds lines of text read from the  
file, String instances. Whatever you do with them, it does not change  
the file.

28.05.2010, × 17:14, Maciej S. ÎÁÐÉÓÁÌ(Á):

> ## works for me
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> wxruby-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

Sergey C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
