AppleScript partially matched string

Hi All,

I’m Javascript developer and is it possible to match the string partially using applescript.

For Ex:

In javascript

Using IndexOf to match the text in the string partially. Could anyone please tell how to find the partially matched text in the string using applescript.

Thanks

I’m not sure I understood you correctly. If you need to find the index of some substring in some text, then here is the AppleScript equivalent:


set aString to "AppleScript partially matched string"
set subString to "partially matched string"

return offset of subString in aString

I was also a bit uncertain as to the meaning of the term “partially matched text in the string”. However, I did a Google search and Javascript string indexOf() is defined as:

The indexOf() method returns the position of the first occurrence of a specified value in a string.
The indexOf() method returns -1 if the value is not found.
The indexOf() method is case sensitive.

https://www.w3schools.com/jsref/jsref_indexof.asp

So, KniazidisR’s answer is entirely correct. Taking that one step further, there are a few differences in that the offset command:

  • is not case sensitive but that is easily changed with a considering-case statement;
  • does not have a start parameter but that can be done with ‘text [start number] thru -1 of theString’; and
  • returns 0 instead of -1 if a match is not found.

If your familiar with RegEx. You can use ASObjC and NSRegularExpression.

Shane also has a Bridged AS Library

https://forum.latenightsw.com/t/regexandstufflib-script-library/2018