Character Code 
Author Message
 Character Code

Hi:

My apologies if this is a ridiculously simple question...

Giiven the following code:

     line = file.readline.strip
     # line = '; some line'

     if line[0].to_s == ';'  # false! line[0] = 59, not ';'
         # ...
     end

My problem is, line[0] returns a fixnum, which doesn't compare with the
';' string.  So... how do perform this comparison?

Thanks,
Cameron

--
"Perhaps a lunatic was simply a minority of one"
    George Orwell



Wed, 05 Jan 2005 03:12:53 GMT  
 Character Code
At Sat, 20 Jul 2002 04:21:08 +0900,

Quote:

> My problem is, line[0] returns a fixnum, which doesn't compare with the
> ';' string.  So... how do perform this comparison?

  line[0] == ?;

or

  /^;/ =~ line

`?;' is a Fixnum literal, represents ascii code of char `;'.



Wed, 05 Jan 2005 03:29:20 GMT  
 Character Code

Quote:
----- Original Message -----


Sent: Friday, July 19, 2002 2:28 PM
Subject: Re: Character Code

> At Sat, 20 Jul 2002 04:21:08 +0900,

> > My problem is, line[0] returns a fixnum, which doesn't compare with the
> > ';' string.  So... how do perform this comparison?

>   line[0] == ?;

> or

>   /^;/ =~ line

> `?;' is a Fixnum literal, represents ascii code of char `;'.

Or: line[0..0] will give you a string.

Hal



Wed, 05 Jan 2005 03:34:32 GMT  
 Character Code
line[0,1]

although i sometimes get errors with that, so

line[0..0]

seems to work best

line[0] just returns the bytecode. go figure.

~transami

Quote:

> Hi:

> My apologies if this is a ridiculously simple question...

> Giiven the following code:

>      line = file.readline.strip
>      # line = '; some line'

>      if line[0].to_s == ';'  # false! line[0] = 59, not ';'
>          # ...
>      end

> My problem is, line[0] returns a fixnum, which doesn't compare with the
> ';' string.  So... how do perform this comparison?

> Thanks,
> Cameron

> --
> "Perhaps a lunatic was simply a minority of one"
>     George Orwell

--
~transami

  _(")_  dobee dobee do...
   \v/  
   ^ ^



Wed, 05 Jan 2005 03:34:33 GMT  
 Character Code

Quote:

> `?;' is a Fixnum literal, represents ascii code of char `;'.

?x being a shortcut for Fixnum literal is cool, but what an
incredible opportunity for code obfuscation!  :-)

This is legitimate Ruby:  "?;??;:?;"

    irb(main):001:0> ?;??;:?;
    59

Heh.

-- Dossy

--

Panoptic Computer Network             web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)



Wed, 05 Jan 2005 07:49:50 GMT  
 Character Code
Working in the other direction from everyone's suggestions, I
might try:

    if line[0].chr == ';'
        # ...
    end

-- Dossy

--

Panoptic Computer Network             web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)



Wed, 05 Jan 2005 07:55:02 GMT  
 Character Code

Quote:

> Working in the other direction from everyone's suggestions, I
> might try:

>     if line[0].chr == ';'
>         # ...
>     end

> -- Dossy

This has got to be the friendliest programming newsgroup in existence.
Thanks for everyone's responses!

Cameron



Wed, 05 Jan 2005 10:11:15 GMT  
 Character Code
Dossy, that's probably the best one --LNO, least number of objects.

Quote:

>     if line[0].chr == ';'
>         # ...
>     end

> -- Dossy

~transami

  _(")_  dobee dobee do...
   \v/  
   ^ ^



Wed, 05 Jan 2005 11:33:22 GMT  
 Character Code
Hi,

In message "Re: Character Code"

|?x being a shortcut for Fixnum literal is cool, but what an
|incredible opportunity for code obfuscation!  :-)

Yeah, I had to leave place for code obfuscation opportunities for the
future contest challengers. ;-)

                                                        matz.



Wed, 05 Jan 2005 23:56:25 GMT  
 Character Code
yeah...we're not jaded :)

sorry for the pun.

todd

Quote:


> >Working in the other direction from everyone's suggestions, I
> >might try:

> >    if line[0].chr == ';'
> >        # ...
> >    end

> >-- Dossy

> This has got to be the friendliest programming newsgroup in existence.
> Thanks for everyone's responses!

> Cameron

--
[It] contains "vegetable stabilizer" which sounds ominous.  How unstable are vegetables?
                                                                Jeff Zahn


Sat, 08 Jan 2005 01:37:05 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. RETURN character code in a STRING !

2. How to convert character code to a String?

3. Help!!! \x## character codes using variables

4. ASCII Character Code

5. ???, that is international character codes in Tcl?

6. multibyte character codes

7. special character codes on different platforms

8. Using actual character codes (0-255) as xmodmap keysyms?

9. Custom keyboard mapping? Character codes 128-160?

10. Attempting to create a variable to hold a hex character code...

11. Summary: convert character to ASCII code?

12. Help: convert character to ASCII code?

 

 
Powered by phpBB® Forum Software