I need help finding substrings within an input...
In my project, I have a very long string and a list of substrings I want to find (they may or may not be present, though).
After finding these substrings, the script should then report back the positions and length of the substrings found.
Any ideas?
Offline
Anyone?
Offline
Well, if it's a single character, I'd recommend looping through, checking for it. Otherwise... try creating substrings of the lengths your checking, starting at the current index. Check if any of those are what you want. Kind of slow and painful, I know. I wish Scratch had native indexOf(). ^^
Offline
ok, list of substrings, presumably held in a real list. And the string presumably held in a variable.
So something like:
set (SubStringCounter) to [0] Repeat <Length of (ListOfSubStrings)> change (SubStringCounter) by [1] repeat until <(counter) = <<Length of (StringHolder)> - [5]>> if <<letter [1] of <item (SubStringCounter) of [ListOfSubStrings v]>> = <letter [1] of (StringHolder)>> set (LetterCounter) to [0] set (MatchCounter) to [0] Repeat <length of <item (SubStringCounter) of [ListOfSubStrings v]>> change (LetterCounter) by [1] if <<letter (LetterCounter) of <item (SubStringCounter) of [ListOfSubStrings v]>> = <letter <(counter) + (LetterCounter)> of (SubStringCounter)>> change (MatchCounter) by [1] else set (MatchCounter) to [0] end end if <(MatchCounter) = <length of <item (SubStringCounter) of [ListOfSubStrings v]>>> stuff happens end end end end----
Offline
Thanks!
Offline