How to check if a numeric string works in a run sequence

Is there a regular expression (or some other way) to check if the lines in the line are in the execution sequence?

For instance,

"123456" will return true
"456789" will return true
"345678" will return true
"123467" will return false
"901234" will return false
+4
source share
2 answers

If all your sequences consist of single-digit numbers, you can solve this by noting that all the correct sequences should be substrings of the longest such sequence, i.e. from "0123456789". Thus, the verification can be performed as follows:

bool res = "0123456789".Contains(str);

Demo on ideon.

+11
source

How about this:

text.Skip(1).Zip(text, (c1, c0) => new { c1, c0 }).All(c => c.c1 - c.c0 == 1)
+2
source

Source: https://habr.com/ru/post/1542112/


All Articles