【发布时间】:2014-05-27 03:26:43
【问题描述】:
是否有正则表达式(或任何其他方式)来检查字符串中的数字是否在运行序列中?
例如,
"123456" will return true
"456789" will return true
"345678" will return true
"123467" will return false
"901234" will return false
【问题讨论】:
是否有正则表达式(或任何其他方式)来检查字符串中的数字是否在运行序列中?
例如,
"123456" will return true
"456789" will return true
"345678" will return true
"123467" will return false
"901234" will return false
【问题讨论】:
如果您的所有序列都由一位数组成,那么您可以通过观察所有正确序列必须是最长此类序列的子字符串(即"0123456789")来解决此问题。所以可以这样检查:
bool res = "0123456789".Contains(str);
【讨论】:
这个怎么样:
text.Skip(1).Zip(text, (c1, c0) => new { c1, c0 }).All(c => c.c1 - c.c0 == 1)
【讨论】: