If you have to parse text or delimited multiline structured data, there are some really great built-in itDuzzit features you should know about. ItDuzzit can automatically parse CSV and pipe-separated values with ease, and make it trivial to loop through the values. In this post, I'll walk through some examples of how to put this feature to use.
Let's start off with a sample duzzit, that just has one output variable, temp, that we use as a holder for the delimited data. Below, you can see I've added some CSV data to this variable. It's pretty common that you'll want to loop through each line of this data and do something with each row. The nice thing is that you can just pass in this entire block of text into a loop step! I want to test this will work, so I create another output variable, count, and increment it for each row found.
Now, when I run this duzzit, I get...
Nifty! What happened was that itDuzzit found the line-feeds in the text, and was able to treat each line as a loop. But what about getting values out of each line? If you've worked with loops in itDuzzit, you'll know that the current value whatever you're looping over is stored in the Loop.Item itDuzzit variable.
Here, I'm taking the Loop.Item value and sticking it in another output variable I've created to temporarily hold the output value, row_temp, each pass through the loop. But, this data is itself delimited by commas, how do I work with each column in the row? You guessed it, just feed the row_temp into another loop inside the current one. Itduzzit will loop through the comma-separated values automatically, allowing you to work one in each loop pass.
Below, you can see I've created an inner loop to go through each column of data, and am checking the Loop.Counter variable to see which column I'm on. If it's the first column, I'm putting it in another temporary variable, english_names.
Now, when I run the duzzit, I'd expect to have the english_names value from the very last row of data, and...
This brings up another important concept in text-looping - the precedence of delimiters. ItDuzzit handles these three delimters in this order:
- line breaks (including CRLF)
- commas (semantic commas enclosed by double-quotes are ignored)
- note, tabs are not currently supported.
If you give some text to a loop, the first delimiter that will be iterated over will be the line breaks, followed by commas, followed by pipes. In our example, that means:
english,latin,phylum dog,canis,chordate fish,piscis,chordate cat,felis,chordate earthworm,lumbricus,annelid
is equivalent to
Keeping this in mind can be useful when building duzzits that output text that may later need to be parsed, but can't handle line-breaks.
Try it! Log in to your itDuzzit account and copy this duzzit to try your hand at looping through text: