All templates
Text ManipulationBeginner
Get Position of Subtext
Robomotion•Updated 6 months ago

Overview
Finds the character index of a substring inside a larger string. A concise demo of the text-search primitives.
Get Position of Subtext
Searching for keywords is usually expected after text extraction, especially when specific values must be handled independently. Robomotion provides "Parse Text" nodes to make parsing text and searching subtexts feasible in flows.
What Get Position of Subtext can do
Core.Dialog.InputBoxtitledGet position of a subtextpromptsPopulate your text:with defaultI love Robomotion!→msg.text_var.- Second
Core.Dialog.InputBoxpromptsPopulate the subtext to look for:with defaultRobomotion→msg.subtext_var. Find Position(Core.Programming.Function,outputs: 2) — computesmsg.position = msg.text_var.indexOf(msg.subtext_var); emits on output0whenmsg.position >= 0, otherwise output1.- Found path:
Build Found Text(Core.Programming.Function) setsmsg.dialog_text = "The subtext '<s>' begins at character <pos>", thenCore.Dialog.MessageBoxtitledFlow ran successfully!shows it. - Not-found path:
Build Not Found Text(Core.Programming.Function) setsmsg.dialog_text = "The subtext '<s>' wasn't found in the given text. ", then a secondCore.Dialog.MessageBoxwith the same title shows it; both paths converge onCore.Flow.Stop.
Behind the scenes
String.prototype.indexOfreturns-1when not found, so the branch guard uses>= 0and keeps the "not found" payload intact on output1.- The match is case-sensitive (
indexOf); swap fortoLowerCase()on both sides if you need case-insensitive matching. - The success message intentionally has a double space before the position number — preserved for visual fidelity with the original template.
- Both branches use
msg.dialog_textas the payload, so the two message-box nodes stay symmetric and easy to restyle together.