c# - 如何检查数字字符串是否在运行序列中

标签 c# .net regex logic

是否有正则表达式(或任何其他方式)来检查字符串中的数字是否在运行序列中?

例如,

"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);

Demo on ideone.

关于c# - 如何检查数字字符串是否在运行序列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23880606/

相关文章:

c# - 使用 HQL 语句按 ID 列表删除多条记录

python - 带 WPF 的 IronPython 中的消息框

c# - .NET 内置 AVL 树?

.net - Azure 队列触发器立即达到 MaxDequeueCount

regex - 跨行替换正则表达式,保留换行符?

c# - Xunit () 中的测试异常

C# DataGridView.DataSource 使用与不使用 BindingSource 的区别

c# - 如何优雅地停止 System.Threading.Timer?

用于提取 FDF 数据的 PHP 正则表达式代码

css - Rails 4 : how to identify and format links, 主题标签和模型属性中的提及?