String interpolation (included): Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 693: | Line 693: | ||
x$ = "little" |
x$ = "little" |
||
print "Mary also had a "; ljust(x$, length(x$)); " lamb"</syntaxhighlight> |
print "Mary also had a "; ljust(x$, length(x$)); " lamb"</syntaxhighlight> |
||
=={{header|Quackery}}== |
|||
'''The Task''' |
|||
Quackery does not have built-in string interpolation. |
|||
'''Not The Task''' |
|||
<code>interpolate$</code> replaces every instance of a specified character in a string with a specified string. Note that the specified string should not include the specified character as this will cause <code>interpolate$</code> to loop indefinitely. |
|||
<syntaxhighlight lang="Quackery"> [ temp put |
|||
swap |
|||
[ 2dup find |
|||
tuck over found while |
|||
over pluck drop |
|||
swap split |
|||
temp share |
|||
swap join join |
|||
again ] |
|||
nip nip temp release ] is interpolate$ ( $ n $ --> $ ) |
|||
$ "Mary had a lamb." char X $ "little" interpolate$ echo$ cr |
|||
$ "Mary had a X lamb." char X $ "little" interpolate$ echo$ cr |
|||
$ "Mary had a X X lamb." char X $ "little" interpolate$ echo$ cr</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Mary had a lamb. |
|||
Mary had a little lamb. |
|||
Mary had a little little lamb. |
|||
</pre> |
|||
==={{header|QBasic}}=== |
==={{header|QBasic}}=== |