Check whether a string contains required text.

substring assertion `string.find` returns a position when the required text is present and `nil` when it is missing.

String Check

text
string_check.lua
Replay: real traced execution (multi-file project)
local text = "trace log"
local found = string.find(text, "trace") ~= nil
local status = "fail"
if found then
    status = "pass"
end
print("text=" .. text)
print("status=" .. status)
local text = "debug log"
local found = string.find(text, "trace") ~= nil
local status = "fail"
if found then
    status = "pass"
end
print("text=" .. text)
print("status=" .. status)
local text = "trace event"
local found = string.find(text, "trace") ~= nil
local status = "fail"
if found then
    status = "pass"
end
print("text=" .. text)
print("status=" .. status)
  1. text ← trace log, found ← true, status ← fail

    1local text→ trace log = "trace log" --@text="debug log", "trace event"2local found→ true = string.find(texttrace log, "trace") ~= nil3local status→ fail = "fail"4if found then
  2. status ← pass

    3local status = "fail"4if foundtrue then5    status→ pass = "pass"6end
  3. print("text=" .. text)

    6end7print("text=" .. texttrace log)8print("status=" .. statuspass)
    outputtext=trace log
    status=pass
  1. text ← debug log, found ← false, status ← fail

    1local text→ debug log = "debug log"2local found→ false = string.find(textdebug log, "trace") ~= nil3local status→ fail = "fail"4if found then5    status = "pass"6end7print("text=" .. textdebug log)8print("status=" .. statusfail)
    outputtext=debug log
    status=fail
  1. text ← trace event, found ← true, status ← fail

    1local text→ trace event = "trace event"2local found→ true = string.find(texttrace event, "trace") ~= nil3local status→ fail = "fail"4if found then
  2. status ← pass

    3local status = "fail"4if foundtrue then5    status→ pass = "pass"6end
  3. print("text=" .. text)

    6end7print("text=" .. texttrace event)8print("status=" .. statuspass)
    outputtext=trace event
    status=pass