1. RE: find if any memers of a set are in another set (blank line finder)?
- Posted by Matthew Lewis <matthewwalkerlewis at YAHOO.COM> Jul 18, 2002
- 398 views
> -----Original Message----- > From: Dan Moyer [mailto:DANIELMOYER at prodigy.net] > I want to be able to discern whether a sequence (a line of > text) is "empty" > (ie, has *only* spaces or tabs or CR or any combination of > those), or if it > has *any* alpha/num/punctuation content at all. In other > words,a "blank" > line finder. And it needs to function as quickly as possible. > > I thought there might be a spiffy way similar to how: > > w = {1, 2, 3} = {1, 2, 4} gives: w={1,1,0} You could do it this way: -- your line is in sequence line constant white_space = { ' ', '\t', '\r', '\n' } sequence l l = repeat(0,length(line)) for i = 1 to length( white_space ) do l += ( line = white_space[i] ) end for if find( 0, l ) then -- something else in there end if Rewritten a-la Carl's one liners: not_blank = find(0, (line = ' ') + (line = '\t') + (line = '\r') + (line = '\n') ) Functionally, but not necessarily speedwise equivalent: not_blank = find(0, (line = ' ') or (line = '\t') or (line = '\r') or (line = '\n') ) > w = {1, 2, 3} or {1, 2, 4} gives me: w= {1,1,1}, which I > don't understand. > (I'm thinking it means that neither 3 nor 4 are zero.) Here's why: w = { 1 or 1, 2 or 2, 3 or 4 } = {1,1,1} > So, is there some way to find if any member of a given set is found in > another set, or some different, good (fast) way to find "blank" lines? I often use this method: for i = 1 to length(line) do if not find(line[i], white_space) then -- found something else! end if end for This would most likely be faster if the first non-whitespace character were toward the beginning of the line. You might also get different results depending on the length of the lines to be tested. While the first method is cool because it uses slick sequence math, I suspect that the last version will be the fastest for your purposes. Matt Lewis