Search string for several substrings

A

ag07

Guest
How can I search a string for several substrings?

Ideally, it would search the main string for all substrings simultaneously, and return thhe results as a string of numbers, like this:

Main string:

Fruit = "apple berry berry orange berry cherry banana apple pineapple grape peach melon pineapple apricot blueberry";

substrings to search for: "berry pineapple apple"

Result: 3 2 2

(3 x "berry", 2 x "pineapple", 2 x "apple")

If it doesn't work to search at the same time, whats the best way to search sequentially?

eg, first search for "berry", then "pineapple", finally "apple"

Can this be done with strings, or should I use lists?

thank you
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Based on your criteria, you might want to use string_count with each of given substrings. Unless the source string is huge and you are doing this a lot of times per frame, [micro-]optimizations wouldn't surpass string_count in performance.
 
A

ag07

Guest
Is there an easy way to use a "for" loop to run all searches, even if I still use string_count?

thanks again
 
Top