I have the following String which is an example row from a SQL database
‘Anytime Goal Scorer - Geelong Cats @ Hawthorn Hawks / Anytime Goal Scorer - Geelong Cats v Hawthorn Hawks / Geelong Cats vs Hawthorn Hawks’
The end goal is to count the total number of occurrences of a target substring.
The target substring that first needs to be stored somewhere is the 4 trailing characters before and after the target character i.e. before and after every v, vs or @ that appears in the String
I then need to do the following:
-
Check if the first 2 occurrences of the target substring are the same:
1a) If the first 2 occurrences aren't the same, we don't need to continue checking and
return 01b) if they are, continue, and check the remainder of the string for more and count
the total number of matches
Note: The target substring is unknown for each row. We just know that the target substring will be either side of the v or vs or @
In the case of the above example, the return would be 3, given that the same substring in all cases appears before and after the v, vs and @, Geelong Cats and Hawthorn Hawks