Saturday, November 27, 2021

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

Vijay_Yukthi
Member
Registered: 2021-04-16
Posts: 40

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

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

Offline

 

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

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2154

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:

Applescript:


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

Offline

 

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

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1133

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.

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.

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


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

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

technomorph
Member
Registered: 2017-12-14
Posts: 218

Re: AppleScript partially matched string

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

Shane also has a Bridged AS Library

https://forum.latenightsw.com/t/regexan … brary/2018

Online

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)