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

后端 未结 8 2253
你的背包
你的背包 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:12

    If you're a linq junkie like me, you'd do it this way

    string s = "abc1def2ghi";
    bool HasNumber = (from a in s.ToCharArray() where a >= '0' && a <= '9' select a).Count() > 0;
    

提交回复
热议问题