Divide String (Split At)
Description
Efficiently split up a string at every nᵗʰ character starting from the right. (Divide a string into equally long parts)
This snippet does not require an addon to function.
Snippet
function splitAt(str: string, n: number) :: strings:
if {_n} > 0:
return regex split {_str} at "(?=(?:.{%{_n}%})+$)"
return {_str}
Applications
broadcast splitAt("ABCDEFG", 2)
# output: A, BC, DE and FG
set {_myString} to "12345678"
broadcast splitAt({_myString}, 3)
# output: 12, 345 and 678
Last updated
Was this helpful?