Something like charIndex, but in a variable...

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Something like charIndex, but in a variable...

Malte Brill
Hi all,

thanks for the replies so far.

The problem with both matchChunk and offset are, that they will return the first occurance of the literal. So in a text like this:


orange banana tomato
banana tomato orange
tomato banana orange

on mouseUp
   local temp,tChar
   put fld 1 into temp
   put offset(char 1 of word 2 of line 3 of temp,temp) into tChar
   set the backcolor of char tChar of fld 1 to "red"
end mouseUp

Will hilite the first b instead of the one on line 3.

@Mark: charIndex does not appear to be working on the templateField. And of course it is slower in 7… :-(

All the best,

Malte



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Something like charIndex, but in a variable...

dunbarxx
Malte.


Just so. Too fast on keyboard, too slow in brain. How about this:



on mouseUp
   put fld 1 into temp
   get the number of chars of word 1 to 8 of temp -- first char
   answer it & "," & the number of chars of word 8 of temp + it
end mouseUp


Craig



Will hilite the first b instead of the one
on line 3.

@Mark: charIndex does not appear to be working on the templateField.
And of course it is slower in 7… :-(

All the
best,

Malte



_______________________________________________
use-livecode
mailing list
[hidden email]
Please visit this url to subscribe,
unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode





-----Original Message-----
From: Malte Brill <[hidden email]>
To: use-livecode <[hidden email]>
Sent: Thu, Apr 30, 2015 10:03 am
Subject: Something like charIndex, but in a variable...


Hi all,

thanks for the replies so far.

The problem with both matchChunk and
offset are, that they will return the first occurance of the literal. So in a
text like this:


orange banana tomato
banana tomato orange
tomato banana
orange

on mouseUp
   local temp,tChar
   put fld 1 into temp
   put offset(char
1 of word 2 of line 3 of temp,temp) into tChar
   set the backcolor of char
tChar of fld 1 to "red"
end mouseUp

Will hilite the first b instead of the one
on line 3.

@Mark: charIndex does not appear to be working on the templateField.
And of course it is slower in 7… :-(

All the
best,

Malte



_______________________________________________
use-livecode
mailing list
[hidden email]
Please visit this url to subscribe,
unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
 
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Something like charIndex, but in a variable...

Thierry Douez
In reply to this post by Malte Brill
> orange banana tomato
> banana tomato orange
> tomato banana orange

Experimenting with regex...
Sorry, couldn't resist :)


function MalteCharIndex T, nWord, nLine,@p1, @p2
   get format( "(?mx)(?: .*? \\n){%d}   (?: (\\w+) [\\W]*){%d}", nLine
-1, nWord)
   return matchChunk( T,  IT, p1, p2)
end MalteCharIndex


and run it this way:

on mouseUp
   put  field "fEntry" into theText
   put 5 into nLine
   put 7 into nWord
   if MalteCharIndex(  theText, nWord, nLine, tStart, tEnd) then
      select  char tStart to tEnd of fld "fEntry"
   else
      beep
   end if
end mouseUp

Did a couple of tests and looks good so far.

Sure, a lot of room for improvement.

Thierry


------------------------------------------------
Thierry Douez - http://sunny-tdz.com
Maker of sunnYperl - sunnYmidi - sunnYmage

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Something like charIndex, but in a variable...

Walt Brown
In reply to this post by dunbarxx
I'm not sure I get it Malte. If you already know which line your target is
on, then just limit the chunk expression to that line.

On Thu, Apr 30, 2015 at 10:51 AM, <[hidden email]> wrote:

> Malte.
>
>
> Just so. Too fast on keyboard, too slow in brain. How about this:
>
>
>
> on mouseUp
>    put fld 1 into temp
>    get the number of chars of word 1 to 8 of temp -- first char
>    answer it & "," & the number of chars of word 8 of temp + it
> end mouseUp
>
>
> Craig
>
>
>
> Will hilite the first b instead of the one
> on line 3.
>
> @Mark: charIndex does not appear to be working on the templateField.
> And of course it is slower in 7… :-(
>
> All the
> best,
>
> Malte
>
>
>
> _______________________________________________
> use-livecode
> mailing list
> [hidden email]
> Please visit this url to subscribe,
> unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
>
>
>
> -----Original Message-----
> From: Malte Brill <[hidden email]>
> To: use-livecode <[hidden email]>
> Sent: Thu, Apr 30, 2015 10:03 am
> Subject: Something like charIndex, but in a variable...
>
>
> Hi all,
>
> thanks for the replies so far.
>
> The problem with both matchChunk and
> offset are, that they will return the first occurance of the literal. So
> in a
> text like this:
>
>
> orange banana tomato
> banana tomato orange
> tomato banana
> orange
>
> on mouseUp
>    local temp,tChar
>    put fld 1 into temp
>    put offset(char
> 1 of word 2 of line 3 of temp,temp) into tChar
>    set the backcolor of char
> tChar of fld 1 to "red"
> end mouseUp
>
> Will hilite the first b instead of the one
> on line 3.
>
> @Mark: charIndex does not appear to be working on the templateField.
> And of course it is slower in 7… :-(
>
> All the
> best,
>
> Malte
>
>
>
> _______________________________________________
> use-livecode
> mailing list
> [hidden email]
> Please visit this url to subscribe,
> unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Something like charIndex, but in a variable...

pmbrig
In reply to this post by Malte Brill
If the example you give is an accurate portrayal of what you are trying to do, why not just:

set the backcolor of char 1 of word 2 of line 3 of temp to "red"    ??

-- Peter

Peter M. Brigham
[hidden email]
http://home.comcast.net/~pmbrig


On Apr 30, 2015, at 10:02 AM, Malte Brill wrote:

> Hi all,
>
> thanks for the replies so far.
>
> The problem with both matchChunk and offset are, that they will return the first occurance of the literal. So in a text like this:
>
>
> orange banana tomato
> banana tomato orange
> tomato banana orange
>
> on mouseUp
>   local temp,tChar
>   put fld 1 into temp
>   put offset(char 1 of word 2 of line 3 of temp,temp) into tChar
>   set the backcolor of char tChar of fld 1 to "red"
> end mouseUp
>
> Will hilite the first b instead of the one on line 3.
>
> @Mark: charIndex does not appear to be working on the templateField. And of course it is slower in 7… :-(
>
> All the best,
>
> Malte
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode