String interpolation (included): Difference between revisions

m
Line 628:
=={{header|APL}}==
<lang apl>
s ← 'Mary had a _ lamb' ⋄ s[s⍳'_'] ← ⊂'little' ⋄ s ← ∊s
s
Mary had a little lamb
Line 637:
∇r ← s sInterp sv
⍝⍝ Interpolate items in sv into s (string field substitution)
⍝ s: string - format string, '_' (underscore)used for interpolation points
⍝ sv: vector - vector of items to interpolate into s
⍝ r: interpolated string
s[('_'=s)/⍳⍴s] ← ⊃¨(⍕¨sv)
r ← ∊s
'Mary had a _ lamb, its fleece was _ as _.' sInterp 'little' 'black' 'night'
Mary had a little lamb, its fleece was black as night.
'Mary had a _ lamb, its fleece was _ as _.' sInterp 'little' 'large' 42
Mary had a little lamb, its fleece was large as 42.
</lang>
67

edits