Multiple Matches --> Find Index of all --> Perhaps Array(Int32)?

Hi there

I have a string, which (is different content), but follows same logic as per picture:

I have tried to both just make a Matches for each of CLUE1, CLUE2 and CLUE3. Controlled that it is correct via count. Set to ‘Exactly’. However, I noticed that I could use “Any” and then put CLUE1, CLUE2 and CLUE3 into same Matches - not sure if it works?

However, I am trying then to acquire the IndexOf of each of them, as I need to use these points as anchor points for what is in between.

Hence, I’ve made an Assign of IndexVariable = myString.IndexOf(myMatch(0).Value). In the case of having a separate Matches per CLUE, then it yiels correctly the Index of first match. However, if I increase, e.g. to 1, 2 or 3, it will still yield the same index and hence not the correct. Frustrating.

I also tried to figure out how I converted the full collection into an array (Int32), such that possibly solve my loop through for indexes…

Not succesful unfortunately. Also tried to make a for each.

Anyone can help me find a way to:
(i) Properly find all matches of CLUE1, CLUE2 and CLUE3
(ii) Get the indexes of them separately, either into array or just working so I can drive a for each using a counter.

Thank you so much in advance!

@Martin_Andersen
maybe you can share a demo txt with us.

have a look here, done as a quick Shot
grafik

strtLine.Select(Function (x, index) strtLine.IndexOf(“CLUE”,index)).Where(function (x) x >=0).Distinct().toList

Doing it a more traditional could look like this
(Please note: I used another text so the positions are different)


grafik
grafik

here the index property helped us
match.Value + " Found on position: " + match.Index.toString

Find starter Help here:
Martin_Andersen.xaml (6.4 KB)

3 Likes

Fantastic! Solves exactly what I was looking for :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.