Convert Integers to Strings

Discussion in 'Ruby' started by Gary Christopher, Jan 5, 2009.

  1. Howdy,

    New to Ruby and looking for some help.
    I would like to prompt the user for input String of single [0 - 9 incl]
    digits e.g 57
    and convert these to word format and store as a single string e.g

    What way is best to go about doing this.

    Should I create a hash of {1 => "one".....} and then iterate through the
    input, swapping digits that match a key with the key's value.

    Thanks a lot
    Gary Christopher, Jan 5, 2009
    1. Advertisements

  2. Gary Christopher

    Ryan Davis Guest

    yes but... gsub is much easier
    Ryan Davis, Jan 5, 2009
    1. Advertisements

  3. Gary Christopher

    Gary Chris Guest

    Thanks mate
    Gary Chris, Jan 5, 2009
  4. Gary Christopher

    Gary Chris Guest

    Nice one Lars.

    Gary Chris, Jan 6, 2009
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.