Wednesday, August 10, 2022

#1 2021-11-18 01:50:20 am

Registered: 2021-04-16
Posts: 65

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.


Last edited by Vijay_Yukthi (2021-11-18 01:55:58 am)



#2 2021-11-18 06:05:09 am

From:: Greece
Registered: 2019-03-03
Posts: 2443

Re: AppleScript partially matched string

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

Last edited by KniazidisR (2021-11-18 06:33:58 am)

Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB



#3 2021-11-18 10:15:41 am

From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1400

Re: AppleScript partially matched string

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.

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.

Last edited by peavine (2021-11-18 03:16:03 pm)

2018 Mac mini - macOS Monterey - Script Debugger 8



#4 2021-11-19 07:21:33 pm

Registered: 2017-12-14
Posts: 255

Re: AppleScript partially matched string

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

Shane also has a Bridged AS Library … brary/2018



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)