charIndex property

Bob Sneidar bobsneidar at iotecdigital.com
Wed Jul 26 13:13:57 EDT 2023


OIC what that does. I suggest having a hidden field, setting the text of that field to your variable, then operating on that field. 

Bob S


> On Jul 26, 2023, at 10:06 AM, Bob Sneidar via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Offset?
> 
> Bob S
> 
> 
>> On Jul 26, 2023, at 10:02 AM, Paul Dupuis via use-livecode <use-livecode at lists.runrev.com> wrote:
>> 
>> 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)?
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list