String concatenation: Difference between revisions

Add Ecstasy example
(An alternate version w/o using the console, different way of declaring string datatypes.)
(Add Ecstasy example)
 
(2 intermediate revisions by 2 users not shown)
Line 773:
b$ = a$ & " world"
print b$</syntaxhighlight>
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="ecstasy">
module StringAppend {
void run() {
String start = "hello";
String finish = " world";
 
// approach #1: add strings together
String approach1 = start + finish;
 
// approach #2: StringBuffer
String approach2 = new StringBuffer()
.append(start)
.append(finish)
.toString();
 
// approach #3: string template
String approach3 = $"{start}{finish}";
 
@Inject Console console;
console.print($|
|Appending strings:
|
| {start=}
| {finish=}
|
| {approach1=}
| {approach2=}
| {approach3=}
|
);
}
}
</syntaxhighlight>
 
{{out}}
<pre>
x$ xec doc/examples/StringAppend
 
Appending strings:
 
start=hello
finish= world
 
approach1=hello world
approach2=hello world
approach3=hello world
</pre>
 
=={{header|Ela}}==
Line 2,465 ⟶ 2,514:
# outputs "hello world"
out s2 endl console</syntaxhighlight>
 
=={{header|Uxntal}}==
<syntaxhighlight lang="Uxntal">|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
 
|0100 @on-reset ( -> )
;str3 ;str1 copy-str
;str3 ;str2 append-str
;str3 print-str
#0a .Console/write DEO
BRK
 
@print-str ( str* -: )
&loop ( -- )
LDAk .Console/write DEO
INC2 LDAk ?&loop
POP2 JMP2r
 
@copy-str ( dest* src* -: )
STH2
&loop ( -- )
LDAkr STH2k STAr INC2 LDAkr STHr INC2r ?&loop
POP2 POP2r JMP2r
 
@append-str ( dest* src* -: )
STH2 end-str STH2r copy-str JMP2r
 
@end-str ( str* -: str* )
!&inner
&loop ( -- )
INC2 &inner LDAk ?&loop
JMP2r
 
@str1 "Uxn 00
@str2 "tal 00
@str3</syntaxhighlight>
 
=={{header|Vala}}==
Line 2,541 ⟶ 2,625:
 
=={{header|Wren}}==
<syntaxhighlight lang="javascriptwren">var s = "Hello, "
var t = s + "world!"
System.print(s)
162

edits