string to integer conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 7ayat 2lro7
    New Member
    • Mar 2010
    • 2

    string to integer conversion

    i want to convert the content of label from string to set of integers
  • Bassem
    Contributor
    • Dec 2008
    • 344

    #2
    A set of integers?

    There is a method to convert a string to many types like integer.
    Convert.ToInt32 (Label1.Text) will do that.

    But a set of strings, you first need to split the text of the label according to your text. ex: a comma-delimited or space, use Label1.Text.Spl it( string [ ] ).


    Thanks,
    Bassem

    Comment

    • 7ayat 2lro7
      New Member
      • Mar 2010
      • 2

      #3
      urgent pls help me with the c# code

      i have form contain label this label contents is string and i want to convert it to integer (ex:the label may have male or female i want to put 1 for male and 0 for female using if else)to be used as inputs to neural network

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Please don't double-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Bassem already told you how to convert a string to an int. Why did you start a second thread on this?

          Originally posted by 7ayat
          i have form contain label this label contents is string and i want to convert it to integer (ex:the label may have male or female i want to put 1 for male and 0 for female using if else)to be used as inputs to neural network
          I love that you are trying to jump in with both feet. And I certainly don't want to discourage. But to be frank, if you can't construct a simple 3 line "if... else" construct then you really don't need to be worrying about neural networking for another few years.

          I would HIGHLY recommend you get a couple books of "Learn C# in 21 days", "My first C# program", "C# for the beginner" etc. You need to work through the basic 'Hello world' applications that we *all* start. You need to learn the C# language before you can write programs that use it. Just as you have to learn the English language before you can expect to write a mystery novel.

          Comment

          • Samishii23
            New Member
            • Sep 2009
            • 246

            #6
            Heres a tip. Google the MSDN website. Then in the MSDN search, use "Convert X to X". Usually just the simple terminology gives good results. Or search in google the exact question. Google searchs go up to 33 words long. Theres bound to be hundreds of others who have asked and others who have responded.

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              Bassem has already provided the Convert.ToInt code
              I have already provided a link to MSDN for how to form an If...else construct.

              Personally I don't care for the MSDN search implication through Bing. I find that if I need to search for something on MSDN that google is the better tool. Searching for "MSDN" plus my need usually takes me right to the answer.
              "MSDN textbox.text" as in this example:
              For all those people who find it more convenient to bother you with their question rather than to Google it for themselves.


              While Samishii and I have slightly varying preferences on details of searching, the underlying concept remains the same: Check the MSDN.

              In the case of the OP's original need though I suspect that he simply did not know what to search for. If one knows so little of C# as to not know there is an if...else construct for making decisions then what would you search for to solve the original question?

              Look at the original question:
              i have form contain label this label contents is string and i want to convert it to integer (ex:the label may have male or female i want to put 1 for male and 0 for female using if else)to be used as inputs to neural network
              The OP feels that he needs to *convert* the contents of the label from a string to an int. It almost sounds as if (s)he is unaware that a label has .text property... or that there will be no actual *conversion* of the label's text but rather the need to use the .text in the decision making process to then set an int variable to either 1 or 0.

              Sure we could just give him/her the one line required:
              Code:
              int MaleFemale = Textbox1.text.ToLower() == "male" ? 1 : 0 ;
              or even a more familiar form:
              Code:
              int MaleFemale = 0; // set to female unless changed
              if Textbox1.text.ToLower() == "male" MailFemale = 1;
              But let's be honest with him/her and ourselves. The OP needs to learn the basics of C# - and do some simple exercises and walk before trying to run. If he cannot be bothered with that much, then we do him a disservice by answering the most basic of questions such as this. Because then we become a crutch to lean on. Why learn the language when someone else will answer every little question?
              How do I add two ints together?
              How do programmaticall y set the text of a label?
              How do tell if a checkbox is checked?


              It is my own personal opinion and I do not speak for Bytes management when I say:
              Originally posted by tlhIn'toq
              If a person can't be bothered to take upon themselves the most basic of reading, the most basic of tutorials, the most basic of books, the most basic of responsibility for their own education and career path, then why would I be bothered to take their education or the problem more seriously than they themselves do?

              Comment

              Working...