# Encoding

**URL:** <https://rubytalk.org/t/encoding/73578>\
**Category:** ruby-talk\
**Created:** [21 April 2016 12:23 UTC](https://rubytalk.org/t/encoding/73578 "2016-04-21T12:23:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_Berger](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@A\_Berger](https://rubytalk.org/u/A_Berger)\
**Post date:** [21 April 2016 12:23 UTC](https://rubytalk.org/t/encoding/73578/1 "2016-04-21T12:23:31Z")

</div>

Hi  
Source of the previous problem was the encoding.

test.rb:  
# encoding: US-8859-1  
p \_\_ENCODING\_\_ # says UTF-8 !?!???  
...gsub(/ü/,...) # failure

The sourcefile is ISO-8859 (because of bad editor) - (( I want to solve the  
ruby-problem, but if we have vi-experts: after :set enc=utf8 :x the file is  
still iso?! ))

How can I input an Umlaut,  
or can get rid of "invalid multibyte char (utf8)"

Datafile is in utf-8, so the error comes from the source.  
Google tells much of Ruby 1.9, but all that didnt help.

Thank you  
Berg

---

<div class="post-metadata">

**Author:** ![stomar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stomar](https://rubytalk.org/u/stomar)\
**Post date:** [21 April 2016 13:29 UTC](https://rubytalk.org/t/encoding/73578/2 "2016-04-21T13:29:41Z")

</div>

> The sourcefile is ISO-8859 (because of bad editor)

[snip]

> get rid of "invalid multibyte char (utf8)"

Save your source as UTF-8.

> but if we have vi-experts [snip]

Really...?!?  
Search for "vim save with new file encoding" or similar.

Regards,  
Marcus

> **···**
>
> Am 21.04.2016 um 14:23 schrieb A Berger:
> 
> --  
> GitHub: [stomar (Marcus Stollsteimer) · GitHub](https://github.com/stomar/)  
> PGP: 0x6B3A101A

---

<div class="post-metadata">

**Author:** ![stomar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stomar](https://rubytalk.org/u/stomar)\
**Post date:** [21 April 2016 13:49 UTC](https://rubytalk.org/t/encoding/73578/3 "2016-04-21T13:49:29Z")

</div>

> Source of the previous problem was the encoding.
> 
> test.rb:  
> # encoding: US-8859-1  
> p \_\_ENCODING\_\_ # says UTF-8 !?!???

No, what it actually should say is

&nbsp;&nbsp;unknown encoding name: US-8859-1 (ArgumentError)

Please, do not post pseudo code with typos in it (it's ISO-8859-1),  
but actual working code that we can simply copy and paste to verify  
your problem.

> ...gsub(/ü/,...) # failure

I can not reproduce a failure.

Again: please show the \*actual\* code and the specific error message.

Regards,  
Marcus

> **···**
>
> Am 21.04.2016 um 14:23 schrieb A Berger:
> 
> --  
> GitHub: [stomar (Marcus Stollsteimer) · GitHub](https://github.com/stomar/)  
> PGP: 0x6B3A101A

---

<div class="post-metadata">

**Author:** ![A\_Berger](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@A\_Berger](https://rubytalk.org/u/A_Berger)\
**Post date:** [21 April 2016 16:11 UTC](https://rubytalk.org/t/encoding/73578/4 "2016-04-21T16:11:56Z")

</div>

Hi  
thats because I cant copy&paste...

x.rb:  
!#/usr/bin/ruby  
# Encoding: xxx  
# encoding=xxx  
p \_\_ENCODING\_\_  
&nbsp;&nbsp;&nbsp;# shows "#\<Encoding:UTF-8\>" (and no error)  
&nbsp;&nbsp;&nbsp;# Ruby version 2.3.0  
Sure you'll get the same results...  
./x.rb

irb works as expected, mri not.

Berg

---

<div class="post-metadata">

**Author:** ![Hassan\_Schroeder](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/hassan_schroeder/32/1838_2.png) [@Hassan\_Schroeder](https://rubytalk.org/u/Hassan_Schroeder)\
**Post date:** [21 April 2016 18:13 UTC](https://rubytalk.org/t/encoding/73578/5 "2016-04-21T18:13:09Z")

</div>

??

11:10 ~/testcases[ruby-2.3.0]$ cat \> x.rb  
#!/usr/bin/env ruby  
# Encoding: xxx  
p \_\_ENCODING\_\_  
11:10 ~/testcases[ruby-2.3.0]$ chmod ugo+x x.rb  
11:10 ~/testcases[ruby-2.3.0]$ ./x.rb  
./x.rb:2: unknown encoding name: xxx (ArgumentError)  
11:11 ~/testcases[ruby-2.3.0]$ ruby -v  
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86\_64-darwin13]  
11:12 ~/testcases[ruby-2.3.0]$

> **···**
>
> On Thu, Apr 21, 2016 at 9:11 AM, A Berger \<aberger7890@gmail.com\> wrote:
> 
> > x.rb:  
> > !#/usr/bin/ruby  
> > # Encoding: xxx  
> > # encoding=xxx  
> > p \_\_ENCODING\_\_  
> > &nbsp;&nbsp;&nbsp;# shows "#\<Encoding:UTF-8\>" (and no error)  
> > &nbsp;&nbsp;&nbsp;# Ruby version 2.3.0  
> > Sure you'll get the same results...  
> > ./x.rb
> > 
> > irb works as expected, mri not.
> 
> --  
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> 
> > **[Hassan Schroeder on about.me](https://about.me/hassanschroeder)**
> >
> > I use about.me to show people what matters most to me.
> 
> twitter: @hassan  
> Consulting Availability : Silicon Valley or remote

---

<div class="post-metadata">

**Author:** ![stomar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stomar](https://rubytalk.org/u/stomar)\
**Post date:** [21 April 2016 18:57 UTC](https://rubytalk.org/t/encoding/73578/6 "2016-04-21T18:57:10Z")

</div>

> thats because I cant copy&paste...

that's ... strange ...

> x.rb:  
> !#/usr/bin/ruby  
> # Encoding: xxx  
> # encoding=xxx  
> p \_\_ENCODING\_\_  
> &nbsp;&nbsp;&nbsp;# shows "#\<Encoding:UTF-8\>" (and no error)  
> &nbsp;&nbsp;&nbsp;# Ruby version 2.3.0  
> Sure you'll get the same results...

No! I already said it works fine for me (using 2.3.0).

Note that the shebang line in your code is wrong;  
you really shouldn't expect us to try and figure out what  
your problem is when you are too careless or lazy to post  
the correct code.

And get a proper mail client and/or editor or whatever it is  
that doesn't allow you to copy&paste or you'll never be able  
to work productively.

Marcus

> **···**
>
> Am 21.04.2016 um 18:11 schrieb A Berger:
> 
> --  
> GitHub: [https://github.com/stomar/](https://github.com/stomar/)  
> PGP: 0x6B3A101A
