A simple sorting problem

I am doing an utility graph for sheets and need a way to pick only the right sheet numbers.
Issue is that projects frequently have Sheet number pairs such as K- and KK- for example as seen here:
image
And right now I am just using string contains:
image
Which works fine for KK- but what if I want to get only K- ?
If I use string.contains with K- as a filter it will also grab KK- because KK- contains K-.

Can anyone help me with this? We allways use characters, dash and then a number eg. KK-01, R-20
and the users will always input the string with dash in graph when using it as seen in 2nd picture. Just need a way to easily differentiate between KK- and K- with minimum inputs possible.

Try using String.StartsWith instead of String.Contains.

  • KK-17 starts with “KK-”.
  • K-14 starts with “K-”.

Just be sure to include the dash as well

5 Likes

To add to Jacob’s suggestion (agreed), if the data is further prefixed and not at the start you could check for contains one and not contains the other, then feed them into an and condition.

3 Likes

Another option: split the string at the dash “-” and group by the prefix value. Then you’ll have all your prefixes grouped and can search for an exact match of any prefix.

3 Likes