string.find reports where a pattern first appears.

start and end Lua reports string positions using one-based indexes, returning both the start and end positions of the match.

Find Position

text
find_position.lua
Replay: real traced execution (multi-file project)
local text = "debug trace"
local startAt, endAt = string.find(text, "trace")

print("text=" .. text)
print("startAt=" .. startAt)
print("endAt=" .. endAt)
local text = "trace debug"
local startAt, endAt = string.find(text, "trace")

print("text=" .. text)
print("startAt=" .. startAt)
print("endAt=" .. endAt)
local text = "runtime trace"
local startAt, endAt = string.find(text, "trace")

print("text=" .. text)
print("startAt=" .. startAt)
print("endAt=" .. endAt)
  1. text ← debug trace, startAt ← 7, endAt ← 11

    1local text→ debug trace = "debug trace" --@text="trace debug", "runtime trace"2local startAt→ 7, endAt→ 11 = string.find(textdebug trace, "trace")34print("text=" .. textdebug trace)5print("startAt=" .. startAt7)6print("endAt=" .. endAt11)
    outputtext=debug trace
    startAt=7
    endAt=11
  1. text ← trace debug, startAt ← 1, endAt ← 5

    1local text→ trace debug = "trace debug"2local startAt→ 1, endAt→ 5 = string.find(texttrace debug, "trace")34print("text=" .. texttrace debug)5print("startAt=" .. startAt1)6print("endAt=" .. endAt5)
    outputtext=trace debug
    startAt=1
    endAt=5
  1. text ← runtime trace, startAt ← 9, endAt ← 13

    1local text→ runtime trace = "runtime trace"2local startAt→ 9, endAt→ 13 = string.find(textruntime trace, "trace")34print("text=" .. textruntime trace)5print("startAt=" .. startAt9)6print("endAt=" .. endAt13)
    outputtext=runtime trace
    startAt=9
    endAt=13