Hi all,
Lists and their functions are probably one of the least-known capabilities in Text Blaze. In this thread, I'd like to share a small snippet that I've been playing around with. I started it as a way for me to better understand how lists work, but then I figured you al might find it useful.
Here it is:
Enter your list items in the box below - one item per row
{formparagraph: name=text}
{list=filter(split(text, "\n"), item -> item <> "")}
{if: count(list)==0}Your list is empty
{else: trim=yes}This is the list {=list}
Your list contains {=count(list)} items
Search for this item in the list (case-sensitive): {formtext: name=string}
{if: string==""}Nothing to show{elseif: includes(list, string)}String "{=string}" is in position {=location(list, string)} in the list{else}Item not in list{endif}{endif}
Now, let me walk you through it.
- I've set up a
formpargraph
command with the name "text". This is where I input the contents of my list - one per line. - Next, I'm creating a list called "list". Here, there are a few things happening. The
split
function is taking the contents of the "text" variable and splitting them up according to line breaks. That's what the "\n" means (think "new line").
Then, thefilter
function is literally filtering the list to remove empty entries. That's whatitem -> item <> ""
means. You don't need to use the word "item" either. Just pick whatever you want. - Now we have the list called "list", which comprises all of my non-empty entries. In other words, if I insert a bunch of empty rows, they will be ignored. And this is important because when I'm using the
count
function to count items in my list, I don't want it to count any empty rows. - Next, we have an
if
command. Here, I want to present a different text based on the contents of my list. If the list count is zero, I get the first bit of text "Your list is empty".
If the count is not zero, I get the other piece of text, which shows me the contents of the list and the count of the items. - In the final bit, I added a
formtext
command named "string". I use the contents of "string" to find out whether they exist in my list, and if they do, which position they're at in the list.
Theincludes
function checks the list to see whether the text extists in it.
Thelocation
function checks which position that bit of text holds in the list.
As it is, this snippet won't do much for you. It's more intended to show you what lists can do and maybe trigger some ideas of how you can use them.
But if you think you might be able to apply these concepts in any of your snippets, let's discuss it in this thread and work on your snippet together.
On a final note, here are the links to the documentation for each of the commands and functions I mentioned in this post:
Hope this helps