Rosetta Code
Substring
Extract substrings from a source string using start offsets and lengths.
Source
rosettacode/popular/substring.vibe
# title: Substring
# source: https://rosettacode.org/wiki/Substring
# category: Rosetta Code
# difficulty: Intro
# summary: Extract substrings from a source string using start offsets and lengths.
# tags: popular, strings, slicing, basics
# vibe: 0.2
def substring(text, start_index, count)
output = ""
offset = 0
while offset < count && start_index + offset < text.length
output = output + text.slice(start_index + offset)
offset = offset + 1
end
output
end
def run
sample = "Vibescript examples"
rows = []
rows = rows.push(["start", "count", "value"])
rows = rows.push([0, 10, substring(sample, 0, 10)])
rows = rows.push([4, 6, substring(sample, 4, 6)])
rows = rows.push([11, 8, substring(sample, 11, 8)])
rows
end
Output
Press run to execute run from this example.