× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




Wouldn't it be faster to call %SCAN in a loop rather than using SCAN folloed by LOOKUP? Seems to me that both SCAN and LOOKUP run loops under the covers. That being the case, if you write your own %SCAN loop, you only have to loop through the array once. If you call SCAN followed by LOOKUP, then you've looped through it twice. Seems like %SCAN would be faster.

The other problem with your solution is that it scans from the left-hand side. Sure, it'd work, but wouldn't it be faster to scan from the right hand side, and abort the process as soon as you found the last underscore you needed? The way you're doing it, it finds every single underscore in the string, and that seems like overkill to me.

Just my opinion, of course.

---
Scott Klement  http://www.scottklement.com


On Wed, 5 Apr 2006, Terry Richardson wrote:

I didn't see anyone mention using the SCAN op code.  I know, everyone here
seems to think /free is a must, but the %scan BIF is lacking something the
good old op code gave us.  You can populate an array with the positions of a
search argument with a string using the SCAN op code.

Take the following string.

'my_string_to_be_scanned_and_fill_array_with_positions_where_underscore_is'

Using the following:

C     '_'           SCAN      ScanString    Array

The resulting array will contain the values
3,10,13,16,24,28,33,39,44,54,60,71,0,0,0,0,0,0,0,......

The number of elements in Array must equal the number of characters in
ScanString.

So to get the word 'where' as you requested, take the resulting array, do a
LOOKUP for the first occurrence of a zero value, and subtract 2 from the
index, save the element value in Y, subtract one more from the index, save
the element value in X, then use the following to get the string you want:

C                   EVAL      WhatIWant = %subst(ScanString:X+1:Y-1)

Note:  I have not tested this, just did this off the top of my head.
****************************************

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.