suve

awful: function: str-implode

Available since rev.40 (v.0.5.4).

Declaration

ascii :str-implode ( array $PIECES , string $GLUE )
ascii :implode-str ( array $PIECES , string $GLUE )

Summary

Takes an array of $PIECES and merges them into a single string, inserting $GLUE between each pair of values.

When omitted, $GLUE defaults to the comma character (,).

Example

# :str-implode example
:set &piece :arr
:set &num i0
:set &txt s''
 
:write s'How many kinds of fruit do you like? '
:readln &num
 
!if :lt $num i1
   :writeln s'Are you a fruit hater? :('
   :exit
!fi
 
:set &idx i1
!while :lt $idx $num
   :write s'Fruit ' $idx s': '
 
   :read &txt
   :set &piece[$idx] &txt
 
   :add &idx i1
!done
 
# Read last element outside loop
:write s'Fruit ' $idx s': '
:read &txt
 
!if :gt $num i1
   :set &txt :add s' and ' $txt
!fi
 
:writeln s"So you're telling me you like " (:str-implode $piece s', ') $txt s'.'
:writeln s"Interesting."

wikipage modified on 2014/0916/1618