You can use the built-in service called “indexOf” as well. This service starts the search from position 0 of the input string, unless you give it a starting position. It will only return the position of the first occurrence of the searchString “local”.
Documentation on built-in services is here.
So do the following if you have need to track how many times “local” is present -
- Calculate the length of the string “local”
- Since case does not matter to you, use “toLower” build-in service to get the lowercase equivalents of both the input and search strings
- Call indexOf and pass the input string, searchString, position (first time it will be 0)
- Note down the current position of searchString (i.e., “local” in your case), returned by indexOf
- Add the position and length values together, to calculate a new starting point (not 0th position) for the search
- Pass new starting position to indexOf, to get the next occurrence (this will be done using “Repeat”)
- Keep a track of all the positions separately (concatenate)
Note that position will be one value less than length, numerically, so calculate the right starting point in step 5. With “encoding” values, you can use this for other languages such as Japanese, Chinese as well.
I hope my algorithm is not confusing