Learn Lua · Tables · Lesson 4 of 5
Splitting text
CoCoCo adds string functions you'd otherwise write yourself. string.split breaks text
apart at a separator, trim removes spaces at both ends, and string.join puts a list
back together:
string.split("a,b,c", ",") --> {"a", "b", "c"}
(" hi "):trim() --> "hi"
string.join(" | ", { "a", "b" }) --> "a | b"
string.contains("rush order", "rush") --> truesplit gives a list, so you can loop over the parts with ipairs and build a new list
with table.insert.
What your code receives
Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.
input = { tags = "gloss, urgent" }Steps
- Return
tags: the tags frominput.tags, split at commas, with spaces trimmed from each. - Add
joined: those tags joined with" | ". - Add
urgent:trueifinput.tagscontains the wordurgent, otherwisefalse.
Show a hint
Split first, then build a new list of trimmed parts. Check for the word in the original text, before it's split.