Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate array of all letters and digits

Tags:

ruby

Using ruby, is it possible to make an array of each letter in the alphabet and 0-9 easily?

like image 601
JP Silvashy Avatar asked Jan 31 '11 01:01

JP Silvashy


People also ask

How do you create an array of alphabets in C++?

void createMine(int i); string alphabet[26] = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };

How do I convert a string to an array in Ruby?

The general syntax for using the split method is string. split() . The place at which to split the string is specified as an argument to the method. The split substrings will be returned together in an array.


1 Answers

[*('a'..'z'), *('0'..'9')] # doesn't work in Ruby 1.8 

or

('a'..'z').to_a + ('0'..'9').to_a 

or

(0...36).map{ |i| i.to_s 36 } 

(the Integer#to_s method converts a number to a string representing it in a desired numeral system)

like image 51
Nakilon Avatar answered Sep 29 '22 22:09

Nakilon