I want to create a function that returns a substring of a specific string from the beginning of said string up to but not including the start of another specific string. Ideas?
So something like:
substrUpTo(theStr, subStr)
so if I inputted substrUpTo("Today is my birthday", "my")
, it would return a substring of the first argument up to but not including where the second argument begins. (i.e. it would return "Today is "
)
set s to "Today is my birthday"
set AppleScript's text item delimiters to "my"
text item 1 of s
--> "Today is "
The built-in offset
command should do it:
set s to "Today is my birthday"
log text 1 thru ((offset of "my" in s) - 1) of s
--> "Today is "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With