Array.index with utf-8

Discussion in 'Ruby' started by Misha Ognev, May 21, 2011.

  1. Misha Ognev

    Misha Ognev Guest

    Hi. I have a problem.

    Windows7

    I have an array with russian symbols. Then I want to find something
    element in it by Array.index(elem).

    In NetBeans 6.9.1 (it settings with utf-8) it works(write index in
    FixNum class), but when i run .rb from a windows, it doesn't work(write
    nil and NilClass). Why?

    P.S. I'm paste the string: "# coding: utf-8" in the start of my script,
    and all other operations works great, exclude this. What I must to do?

    Thanks in advance

    --
    Posted via http://www.ruby-forum.com/.
    Misha Ognev, May 21, 2011
    #1
    1. Advertising

  2. Misha Ognev

    Peter Zotov Guest

    On Sun, 22 May 2011 04:44:54 +0900, Misha Ognev wrote:
    > Hi. I have a problem.
    >
    > Windows7
    >
    > I have an array with russian symbols. Then I want to find something
    > element in it by Array.index(elem).
    >
    > In NetBeans 6.9.1 (it settings with utf-8) it works(write index in
    > FixNum class), but when i run .rb from a windows, it doesn't
    > work(write
    > nil and NilClass). Why?
    >
    > P.S. I'm paste the string: "# coding: utf-8" in the start of my
    > script,
    > and all other operations works great, exclude this. What I must to
    > do?
    >
    > Thanks in advance


    Are you sure that your file is really saved in UTF-8? Under Russian
    Windows,
    for example, the standard Notepad will save it either in CP1251, which
    is the
    ANSI locale, or in UTF-16. IIRC in WinXP notepad there is no way to
    save text in
    UTF-8 (I may be wrong through).

    --
    WBR, Peter Zotov.
    Peter Zotov, May 21, 2011
    #2
    1. Advertising

  3. Misha Ognev

    7stud -- Guest

    Misha Ognev wrote in post #1000115:
    > Hi. I have a problem.
    >


    Post 5 lines or less of code that demonstrates the problem. Also, state
    what version of ruby you are using.

    --
    Posted via http://www.ruby-forum.com/.
    7stud --, May 21, 2011
    #3
  4. Misha Ognev

    Misha Ognev Guest

    > Also, state what version of ruby you are using.
    1.9.2

    > Post 5 lines or less of code that demonstrates the problem.


    pos = d.index(@buttonarray.get_value)+1

    I have a big system with a diary, IO, wxRuby et.c. I can't send you code
    you understand in 5 strokes.

    > Are you sure that your file is really saved in UTF-8? Under Russian

    Windows, for example, the standard Notepad will save it either in
    CP1251...
    File in UTF-8, all works with it fine. Only index function is worng

    --
    Posted via http://www.ruby-forum.com/.
    Misha Ognev, May 22, 2011
    #4
  5. Misha Ognev wrote in post #1000176:
    >> Post 5 lines or less of code that demonstrates the problem.

    >
    > pos = d.index(@buttonarray.get_value)+1


    STDERR.puts "d.encoding=#{d.encoding}"
    STDERR.puts "value.encoding=#{@buttonarray.get_value.encoding}"

    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, May 22, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JJBW
    Replies:
    1
    Views:
    10,004
    Joerg Jooss
    Apr 24, 2004
  2. =?Utf-8?B?QXNoYQ==?=
    Replies:
    3
    Views:
    408
  3. Arifi Koseoglu
    Replies:
    2
    Views:
    943
    Arifi Koseoglu
    Apr 13, 2004
  4. Shawn W_
    Replies:
    5
    Views:
    257
    Aldric Giacomoni
    Sep 16, 2009
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    256
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page