Comparing Numerical Values in a String

I am working on a particular automation and part of the process needs to validate a payment history field. This field is currently 96 characters long in string format and contains payment history for a particular account. The string could contain any number 0-9 as well as certain letters representing different statuses. An example portion of a string could be β€œ00001230000111222223334000B” and any combination.

The thing I need is to look at each individual character in a string and confirm that the following number is at most one more than the current one or is a letter/less than. So for example this string β€œ00012301112” would be valid but β€œ00012366600” would not since it can not go from 3 to 6 in one position.

What is an easy way to do this since it is in string format?

Hello,

At first glance, a very crude solution: you could make chunks by splitting on 0 and/or letter clusters and check the condition for each chunk. If it doesn’t match, you can search the chunk position.

import System.Text.RegularExpressions

Assign (Array Of String)
chunks = Regex.Split(chain, "[0A-Z]+")

Assign (String)
condition = "^(1+|1+2+|1+2+3+|1+2+3+4+|1+2+3+4+5+|1+2+3+4+5+6+|1+2+3+4+5+6+7+|1+2+3+4+5+6+7+8+|1+2+3+4+5+6+7+8+9+)$"

Assign (Array Of String)
results = chunks.Where(Function(chunk) Regex.IsMatch(chunk, condition)).ToArray

Assign (Array Of String)
fails = chunks.Where(Function(chunk) chunk <> "" And Not Regex.IsMatch(chunk, condition)).ToArray

1 Like

@Tyler294

Please have a look on this XAML.
1.I loop for every character in string.
2. I checked for condition
3. It is valid for above two test cases.

Main.xaml (8.7 KB)