String interpolation (included): Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Quackery}}: replaced a note in the (accidentally duplicated/just removed) Quackery entry)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(2 intermediate revisions by 2 users not shown)
Line 359:
Mary had a little lamb.
</pre>
 
Algol 68 allows a string to be used as a file, the following (based on the above) uses this to construct the string which can then be further processed. In this sample, variable strings and formats are used though in general it would be hard to construct the extraf format at run-time as Algol 68 has no facilities to construct formats on the fly.
 
<syntaxhighlight lang="algol68">
BEGIN
FILE str file;
STRING mhl;
associate( str file, mhl );
 
STRING extra := "little";
TO 2 DO
putf( str file, ( $"Mary had a "g" lamb."$, extra ) );
print( ( "1 result is: {{", mhl, "}}", newline ) );
mhl := "";
"supposedlly-" +=: extra
OD;
 
FORMAT extraf := $"little"$;
TO 2 DO
putf( str file, ( $"Mary had a "f(extraf)" lamb."$ ) );
print( ( "2 result is: {{", mhl, "}}", newline ) );
mhl := "";
extraf := $"medium-sized"$
OD
END
</syntaxhighlight>
 
{{out}}
<pre>
1 result is: {{Mary had a little lamb.}}
1 result is: {{Mary had a supposedlly-little lamb.}}
2 result is: {{Mary had a little lamb.}}
2 result is: {{Mary had a medium-sized lamb.}}
</pre>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
Line 687 ⟶ 722:
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="qbasic">10 x$ = "big"
20 print "Mary had a "; x$; " lamb"</syntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">x$ = "big"
Line 693 ⟶ 732:
x$ = "little"
print "Mary also had a "; ljust(x$, length(x$)); " lamb"</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 x$ = "big"
20 print "Mary had a "; x$; " lamb"</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|QBasic}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">10 X$ = "big"
20 PRINT "Mary had a "; X$; " lamb"
30 X$ = "little"
40 PRINT USING "Mary also had a & lamb"; X$
50 END</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
<syntaxhighlight lang="qbasic">10 LET X$ = "BIG"
20 PRINT "MARY HAD A "; X$; " LAMB"
30 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|QBasic}}===
Line 701 ⟶ 765:
' this code above doesn't modify the first string subsustituting a piece of it with another string
'surely it gives the right output on the screen</syntaxhighlight>
 
==={{header|Quite BASIC}}===
<syntaxhighlight lang="qbasic">10 LET X$ = "BIG"
20 PRINT "Mary had a "; x$; " lamb"</syntaxhighlight>
 
==={{header|True BASIC}}===
Line 712 ⟶ 780:
PRINT "Mary also had a "; outstring$; " lamb"
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "String append"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
X$ = "big"
PRINT "Mary had a "; X$; " lamb"
END FUNCTION
END PROGRAN</syntaxhighlight>
 
==={{header|Yabasic}}===
Line 2,257 ⟶ 2,337:
 
=={{header|Wren}}==
<syntaxhighlight lang="javascriptwren">var s = "little"
var t = "Mary had a %(s) lamb"
System.print(t)</syntaxhighlight>
9,482

edits