How to check if an integer includes a certain number in c#

后端 未结 2 1888
情书的邮戳
情书的邮戳 2021-01-17 09:27

Is there a way I can check Integers if they contain a certain number in C#?

For example:

I want to check for 7. When I enter 17, the code

相关标签:
2条回答
  • 2021-01-17 09:42

    Convert it to a string, then use String.Contains:

    int i = 17;
    int j = 28
    int k = 7;
    
    bool a = i.ToString().Contains(k.ToString());
    bool b = j.ToString().Contains(k.ToString());
    
    0 讨论(0)
  • 2021-01-17 09:45
    int number = 17;
    int digit = 7;
    bool result = number.ToString().Contains(digit.ToString());
    
    0 讨论(0)
提交回复
热议问题