To check whether the string value has numeric value or not in C#

后端 未结 8 2249
你的背包
你的背包 2021-02-14 02:29

I am having an string like this

string str = \"dfdsfdsf8fdfdfd9dfdfd4\"

I need to check whether the string contains number by looping through the array.

相关标签:
8条回答
  • 2021-02-14 03:15

    What about a regular expression:

    bool val = System.Text.RegularExpressions.Regex.IsMatch(str, @"\d");
    
    0 讨论(0)
  • 2021-02-14 03:15

    Combining parts of Kamals answer and Tristars answers give...

    str.Any(char.IsNumber)
    

    which I think is the most succinct and readable way, instead of a regex

    0 讨论(0)
提交回复
热议问题