Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
set itemDelimiter to tab
filter lines of tList where item 2 of each = 1
But the variable it doesn't contain anything.
Of course, I could do the same thing with a loop but, as filtering is optional, it will take longer (I would have to test filtering on each lines, or write 2 loops).
on mouseUp
repeat with y = 1 to 3
put "A" & tab & y & tab & "B" into line y of temp
end repeat
set the itemDel to tab
filter lines of temp where item 2 of each <> 2
end mouseUp
Not that it matters in this case, but "lines" is the default for the filter command, so it is superfluous.
I realize that I didn't understand the Dictionary, where it is said:
If the filter command is used on a filterSource which is not a container, and no targetContainer is specified, the filtered string or array will be placed in the it variable.
Also, and sorry if I misunderstand, there is no need to either use numToCodepoint(9) or describe it as [tab] - tab is a keyword and you can use it as is in your code and it will be understood as numToCodepoint(9)…
I'm pretty sure [TAB] was meant just as an indicator here in the forum where typing the actual character could be mistaken for a space. I do the same thing.
Off the top of my head, this should also work and changes the variable itself:
jacque wrote: Tue Aug 10, 2021 6:18 pm
I'm pretty sure [TAB] was meant just as an indicator here in the forum where typing the actual character could be mistaken for a space. I do the same thing.
It matters little, but...
Zax wrote: Tue Aug 10, 2021 2:18 pm
Sorry if I wasn't clear: "[TAB]" means a tab character (ASCII 9)
@Craig - i stand corrected; i really meant 'reserved word' but got lazy
set itemdel to tab
repeat for each line L in myData
if (item 2 of L = 1) then put L & CR after myVar
end repeat
delete char -1 of myVar
MyVar is now the "filtered" myData. Always, reliable & very fast.
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
put "*" & tab & "1" & tab & "*" into tFilter
filter tList with tFilter
This works on your sample list, but I had to remove the spaces around the tabs. I assume your real list has no spaces. If it does, just add a space before and after the "1" in the filter string.
I also noticed when I copied your example that there are several invisible characters in the text. They may be due to the forum formatting, but check. You'll want to remove those, since the filter command will see them and nothing will match.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
too often I got the "filter" command to return things I'd not meant it to.
@Axwald. The filter command is on the same road that regex is. In fact, I suspect the two of collusion.
I have used filter successfully, but always seem to struggle a bit to get it right. I also feel more comfortable with a "filtering' loop. The cost is speed, but that said, a loop has more power and flexibility, especially in being able to work multiple "filters" in a single line of code.
jacque wrote: Tue Aug 10, 2021 9:22 pmThis works on your sample list, but I had to remove the spaces around the tabs. I assume your real list has no spaces. If it does, just add a space before and after the "1" in the filter string.
Right, Jacqueline.
I didn't know tab was allowed in the forum editor.
@AxWald : variable is duplicated in your example. Ii could be interesting to compare processing time with large list.
Also, I wanted to use the Filter command because I find it very elegant. This is a good example of the power of LC, IMHO.