Re: Find subarray in an array? [message #3562] |
Wed, 22 February 1995 23:23 |
Jackel
Messages: 30 Registered: April 1993
|
Member |
|
|
In article <3i018j$69q@gwdu19.gwdg.de> kettmann@linrap.dnet.gwdg.de () writes:
> I am looking for an efficient/elegant solution to find "sync words" within an
> array.
> The sync word consists of 3 consecutive bytes, for example:
> SYNC = ['14'XB, '6f'XB, '2e'XB]
> and I need to find the position of the first element of SYNC within an array
> (it is not granted that there is any SYNC, it there could be more than one
> SYNC).
If your data is a byte stream, then you might try converting it to a string,
and using the STRPOS command. For example
sync= [1B, 2B, 3B]
syncstring= STRING(sync) ;convert to a 3 character string
data= [0B, 1B, 1B, 2B, 3B, 0B] ;create a dummy data stream containing "sync"
datastring= STRING(data) ;convert it to a string
syncpos= STRPOS(datastring,syncstring,0)
will find the first (if any) occurance of "sync" within "data". However, I
haven't tested to see if it is any faster than 3 successive WHERE's.
Brian Jackel
University of Western Ontario
|
|
|