BUCL.io / explode
Trennt einen Text in mehrere Texte auf.
Beispiel
{res} explode "," "one,two,three"
Quellcode
#explode
#description: Divides one string into multiple texts
#description-DE: Trennt einen Text in mehrere Texte auf.
#sample: {res} explode "," "one,two,three"
#to test direct: {input} = "," "we,are,0simple,texts" "with,more"
#read input numbered and named
{delimiter} = ""
{parts} = {input}
{inputCount} count {input}
if {inputCount} >= 2
{delimiter} = {input/0}
{parts} slice 1 0 {input}
if {input/delimiter}
{delimiter} = {input/delimiter}
if {input/parts}
{parts} = {input/parts}
#make flat concatenated string of all parameters (incl. named onces)
{flatConcat} = ""
{loop} each {parts}
if {loop/first}
{flatConcat} = {loop/value}
else
{flatConcat} = "{flatConcat}{delimiter}{loop/value}"
#loop though that string char per char and build up new exploded list
{result} = ""
{lastCharWasDelimiter} = 0
{flatConcatLength} length {flatConcat}
{loop} repeat 0 {flatConcatLength}
{char} = {flatConcat/0/{loop/index}}
if {char} = {delimiter}
{lastCharWasDelimiter} = 1
else
if {lastCharWasDelimiter}
{lastCharWasDelimiter} = 0
{result} = {result} {char}
else
{result} = "{result}{char}"
{output} = {result}