Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7890947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:29:21+00:00 2026-06-03T06:29:21+00:00

my Question is how I can convert the STDIN of cmd ARGV or gets

  • 0

my Question is how I can convert the STDIN of cmd ARGV or gets from hex to ascii

I know that if I assigned hex string to variable it’ll be converted once I print it

ex

hex_var = "\x41\41\x41\41"
puts hex_var

The result will be

AAAA

but I need to get the value from command line by (ARGV or gets)

say I’ve this lines

s = ARGV

puts s
# another idea
puts s[0].gsub('x' , '\x')

then I ran

ruby  gett.rb \x41\x41\x41\x41 

I got

\x41\x41\x41\x41

is there a way to get it work ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:29:23+00:00Added an answer on June 3, 2026 at 6:29 am

    There are a couple problems you’re dealing with here. The first you’ve already tried to address, but I don’t think your solution is really ideal. The backslashes you’re passing in with the command line argument are being evaluated by the shell, and are never making it to the ruby script. If you’re going to simply do a gsub in the script, there’s no reason to even pass them in. And doing it your way means any ‘x’ in the arguments will get swapped out, even those that aren’t being used to indicate a hex. It would be better to double escape the \ in the argument if possible. Without context of where the values are coming from, it’s hard to say with way would actually be better.

    ruby gett.rb \\x41\\x41
    

    That way ARGV will actually get ‘\x41\x41’, which is closer to what you want.

    It’s still not exactly what you want, though, because ARGV arguments are created without expression substitution (as though they are in single quotes). So Ruby is escaping that \ even though you don’t want it to. Essentially you need to take that and re-evaluate it as though it were in double quotes.

    eval('"%s"' % s)
    

    where s is the string.

    So to put it all together, you could end up with either of these:

    # ruby gett.rb \x41\x41
    
    ARGV.each do |s|
      s = s.gsub('x' , '\x')
      p eval('"%s"' % s)
    end
    # => "AA"
    
    # ruby gett.rb \\x41\\x41
    
    ARGV.each do |s|
      p eval('"%s"' % s)
    end
    # => "AA"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that you can convert a float into a string using NSString *myString
I got a simple question in Java: How can I convert a String that
My question can be boiled down to, where does the string returned from stringstream.str().c_str()
Here is my simple question We can convert integer, float, double to String like
I know this question can be answered by searching in google. But I have
I am trying to create a function that can convert a month number to
I have a string I need to convert back to a date. I can
Can I convert Class into Dictionary<string, string>? In Dictionary I want my class properties
Is there a way that I can convert the to_be_approved by method in the
I have a question Can we convert date 20-06-2011 (dd-mm-yyyy) into 0611 using sql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.