使用LINQ检查字符串中是否至少包含一个数字 [英] Check if a string has at least one number in it using LINQ

查看:107
本文介绍了使用LINQ检查字符串中是否至少包含一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果字符串中包含任何数字字符,最简单,最短的LINQ查询将返回true.

I would like to know what the easiest and shortest LINQ query is to return true if a string contains any number character in it.

推荐答案

"abc3def".Any(c => char.IsDigit(c));

更新:正如 @Cipher 所指出的,实际上它可以做得更短:

Update: as @Cipher pointed out, it can actually be made even shorter:

"abc3def".Any(char.IsDigit);

这篇关于使用LINQ检查字符串中是否至少包含一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆