Qu

insert

Builtin index · Collections & strings

result = insert(s, i, text)

Input: s, i, text · Output: result

What it is

s and text are Strs; i (number, 0-based character position) is where text is spliced in.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = insert(s, i, text)
s Strs and text are Strs.
i numberi (number, 0-based character position) is where text is spliced in.
text Strs and text are Strs.
result Str
Returns a new Str; s itself is untouched.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

path = "report_final_v2.txt"
print(ends_with(path, ".txt"))         # true

print(index_of(path, "_"))              # 6

print(last_index_of(path, "_"))         # 12

print(insert("helloworld", 5, ", "))    # "hello, world"

print(remove("hello, world", ", "))     # "helloworld"

line = "key: value"
print(after(line, ": "))                # "value"

print(before(line, ": "))               # "key"

full = "a/b/c.txt"
print(after_last(full, "/"))            # "c.txt"

print(before_last(full, "/"))           # "a/b"

output
true
6
12
hello, world
helloworld
value
key
c.txt
a/b

from collections-strings

How it works

insert(collection, index, value) — returns a NEW list/vector with value inserted before position index (so index == length appends at the end); same immutable- return convention as remove/append. Dispatches on arg0's type: a Vec insert must itself be numeric (it stays a plain numeric vector, never silently promoted to a heterogeneous List), a List insert accepts anything.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.