Results 1 to 5 of 5

Thread: if statement

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    if statement

    if i have the following array:
    Code:
    private string[] digits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
    and i then want to check if a string contains any of these numbers, could i do something like this:


    Code:
    String test ="1+2+3";
    
    if(test equals any of the digits in 'digits')
    {
         // Do stuff
    }

  2. #2
    Lively Member
    Join Date
    Jun 2003
    Posts
    124

    Re: if statement

    i would use regular expressions

    you need to add the following
    Code:
    using System.Text.RegularExpressions;

    the actual code would be:
    Code:
     
    String strInput = "Your input text!!!11";
    string strPatern = "[0-9]";
    Match myMatch = Regex.Match(strInput, strPatern);
    if(myMatch.Success)
    {
    //dostuff
    }

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: if statement

    Thanks ill try it out

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: if statement

    Just ran into a snare...how about + - and *??

  5. #5
    Lively Member
    Join Date
    Jun 2003
    Posts
    124

    Re: if statement

    Quote Originally Posted by carstenht
    Just ran into a snare...how about + - and *??

    think i answered that in your other thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width