Learn Lua · Strings · Lesson 3 of 3
Finding and changing text
Strings have functions you can call with a colon: name:upper() is the same as
string.upper(name).
local code = "fly-a4"
code:upper() --> "FLY-A4"
code:sub(1, 3) --> "fly"sub(from, to) takes characters by position, starting at 1. string.match finds text
by a pattern: %d+ means one or more digits, and %a+ one or more letters:
string.match("SO-1042", "%d+") --> "1042"
string.match("SO-1042", "%a+") --> "SO"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 = { code = "fly-a4", reference = "SO-1", name = "Flyer" }Steps
- Return
code:input.codein capital letters. - Add
number: the digits frominput.reference, such as"1042"from"SO-1042". - Add
short: the first three characters ofinput.name.
Show a hint
Each field is one call. A pattern describes the kind of characters you want, not the exact text, so it works for any reference.