Skip to content

How can i convert Words (one,two,three) to numbers(1,2,3)

Sindhu Nallan

Asked Sep 3, 2008, 1:09 PM EDT1 answer
Share
LinkedInX

Hi all,

i am trying to convert words( i.e one,two,three....) to numbers(1,2,3....).Convert.ToInt32 or Parse did not work. Can anybody please guide me how can i achieve that.

Thanks a lot in advance.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    C#
    Create an int variable in the main form class. When the user enters/selects the number option (One, Two, Three, etc.) from the object (combo box, label, etc.) have that selection assign the corresponding number to the int variable. For example:
    public partial class frmMain:Main
    {
    int intNumber;
    //Using a combo box
    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
    switch (comboBox1.Text)
    {
       case "One":
          intNumber = 1;
          break;
       case "Two":
          intNumber = 2;
          break;
       case "Three":
          intNumber = 3;
          break;
       default:
          break;
    }
    }
    }
    0