Interpret a comma seperated list of ints as a string

Getting input like 100,101,102,103 and knowing it is supposed to represent characters but all you have is the bytes can be annoying, so here we go a quick way of writing it out as a text file.

File.open("out.txt", "w") do |f|
  content = File.open("bytes.csv").read
  f.write(content.split(",").map(&:to_i).pack("c*"))
end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.