charIndex property

Paul Dupuis paul at researchware.com
Wed Jul 26 13:02:50 EDT 2023


If I have some text in a field, I can use the "charIndex" property (see 
Dictionary) to obtain teh character position of the first character of a 
chunk.

For example, if the field contains:

The quick brown fox jumps over the lazy dog. The lazy dog was named "Oz".

The lazy dog was a great dog.

Then there are 3 instances of  "lazy dog"

trueWord 8 to 9 of the field,  11 to 12, and 17 to 18

You can also determine that first instance "lazy dog" is in sentence 1 
to 1 (or just sentence 1) of the field, the 2nd is in sentence 2, and 
the 3rd in sentence 3

And you can determine that the first 2 instances are in paragraph 1 and 
the 3rd instance of "lazy dog" is in paragraph 2 (using the trueWord, 
sentence, and paragraph chunk types)

charIndex lets me determine the start of a sentence or paragraph, such as:

the charIndex of sentence 1 to 1 of fld X --> 1 and the charIndex of 
sentence 2 of fld X --> 46 and the charIndex of sentence 3 of fld "X" --> 75

the charIndex of paragraph 1 of fld X --> 1 and the charIndex of 
paragraph 2 of fld X --> 75

My question is, charIndex appear to ONLY work on an actual field object 
(visible or invisible). You get execution errors if you try say:

put the charIndex of word 8 of the text of the templateField

put the charIndex of word 8 of the templateField

put the charIndex of word 8 of tVar

Does anyone know of a clever way to do the equivalent of the charIndex 
for an arbitrary chunk expression for a container/variable (i.e. not an 
actual field object)?



More information about the use-livecode mailing list