String append: Difference between revisions

m
(GDScript)
 
(21 intermediate revisions by 15 users not shown)
Line 172:
<pre>
123456789!
</pre>
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="c">
#include <jambo.h>
 
Main
r="un corderito", s="María tenía", t="felpudo"
Multicat ( s," ",r," ",t ),Get utf8, and print it
d=0
Let ' d := Utf8( Cat( Cat ( s, " un " ), t ) )'
Printnl ( "\n",d )
End
</syntaxhighlight>
{{out}}
<pre>
María tenía un corderito felpudo
María tenía un felpudo
</pre>
 
Line 364 ⟶ 384:
r₁
Return</syntaxhighlight>
 
 
=={{header|BASIC}}==
Line 380 ⟶ 398:
</syntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">a$ = "He"
a$ = a$ & "llo"
a$ = a$ + " Wo"
a$ += "rld"
a$ &= "!"
print a$</syntaxhighlight>
 
==={{header|BBC BASIC}}===
Line 396 ⟶ 421:
{{out}}
<pre>HELLO WORLD!</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 a$ = "Hello"
20 a$ = a$ + " World!"
30 print a$</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Applesoft Basic}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">10 LET a$ = "Hello"
20 LET a$ = a$ + " World!"
30 PRINT a$</syntaxhighlight>
 
==={{header|IS-BASIC}}===
Line 401 ⟶ 444:
110 LET S$=S$&" World!"
120 PRINT S$</syntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">a$ = "He"
a$ = a$ & "llo"
a$ = a$ + " Wo"
a$ += "rld"
a$ &= "!"
print a$</syntaxhighlight>
 
==={{header|Liberty BASIC}}===
Line 415 ⟶ 450:
a$ = a$ ; "!"
print a$</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|QBasic}}===
Line 424 ⟶ 462:
a$ = a$ + " World!"
PRINT a$</syntaxhighlight>
 
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Run BASIC}}===
Line 439 ⟶ 480:
PRINT a$
END</syntaxhighlight>
 
==={{header|uBasic/4tH}}===
<syntaxhighlight lang="qbasic">a := "Hello"
a = Join (a, " World!")
Print Show(a)</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "String append"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
a$ = "Hello"
a$ = a$ + " World!"
PRINT a$
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
Line 449 ⟶ 509:
print a$</syntaxhighlight>
 
 
=={{header|Binary Lambda Calculus}}==
BLC program
<pre>18 16 46 80 05 bc bc fd f6 e0 69 6f 6e</pre>
based on https://github.com/tromp/AIT/blob/master/rosetta/catstrings.lam
appends "ion" to "on" to output "onion".
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">str ← "oneTwo"
 
•Out str ∾↩ "Three"
 
str</syntaxhighlight>
{{out}}
<pre>oneTwoThree
"oneTwoThree"</pre>
 
=={{header|Bracmat}}==
Line 598 ⟶ 674:
<pre>Hello world!</pre>
 
=={{header|Dart}}==
<syntaxhighlight lang="dart">void main() {
String str = "Hello";
str = str + " World!";
print(str);
}</syntaxhighlight>
 
=={{header|DBL}}==
Line 676 ⟶ 758:
 
=={{header|Elena}}==
ELENA 46.x :
<syntaxhighlight lang="elena">import extensions'text;
import extensions'text;
 
public program()
{
var s := StringWriter.load("Hello");
s.append:(" World");
console.printLine:writeLine(s).readChar()
}</syntaxhighlight>
 
Line 721 ⟶ 802:
(buffer-string)))
;; => "foobar"</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
^|EMal has mutable strings;
|the append method changes the value in-place.
|^
text hello = "Hello, "
hello.append("world!")
writeLine(hello)
</syntaxhighlight>
{{out}}
<pre>
Hello, world!
</pre>
 
=={{header|Erlang}}==
Line 844 ⟶ 939:
String append
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
Str255 s
 
s = "Hello"
s += " World!"
 
print s
 
HandleEvents
</syntaxhighlight>
 
=={{header|Gambas}}==
Line 992 ⟶ 1,099:
 
=={{header|Java}}==
There are multiple ways to append string values in Java.<br />
The most common way is through the plus operator.
<syntaxhighlight lang="java">
String string = "abc" + "def";
</syntaxhighlight>
Which can also be written as
<syntaxhighlight lang="java">
String string = "abc";
string += "def";
</syntaxhighlight>
There is also the ''String.concat'' method
<syntaxhighlight lang="java">
String string = "abc".concat("def");
</syntaxhighlight>
You could use a ''StringBuilder'' object if you're appending multiple strings.
<syntaxhighlight lang="java">
StringBuilder string = new StringBuilder();
string.append("abc").append("def");
</syntaxhighlight>
''StringBuilder'' also conveniently lets you insert strings within strings.<br />
So, you can also append a string as follows
<syntaxhighlight lang="java">
StringBuilder string = new StringBuilder();
string.append("abc");
string.insert(3, "def");
</syntaxhighlight>
A less common approach would be to use the ''String.format'' or ''String.formatted'' methods.
<syntaxhighlight lang="java">
String string = String.format("%s%s", "abc", "def");
</syntaxhighlight>
<syntaxhighlight lang="java">
String string = "%s%s".formatted("abc", "def");
</syntaxhighlight>
All of these methods will produce the following string
<pre>
abcdef
</pre>
<br />
Alternately
<syntaxhighlight lang="java">String sa = "Hello";
sa += ", World!";
Line 1,058 ⟶ 1,204:
<pre>"Hello, world!"</pre>
 
=={{header|K}}==
<syntaxhighlight lang=K>h: "hello "
h,: "world"
h
"hello world"</syntaxhighlight>
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">fun main(args: Array<String>) {
Line 1,113 ⟶ 1,264:
{{out}}
<pre>Hello, World!</pre>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
myText is text
 
procedure:
store "LD" in myText
in myText join myText "PL"
display myText lf
</syntaxhighlight>
{{out}}
<pre>
LDPL
</pre>
 
=={{header|Lingo}}==
Line 1,151 ⟶ 1,316:
 
=={{header|M2000 Interpreter}}==
Documents in M2000 are objects with paragraphs. From Version 12 we can use variable names for strings without suffix $, although a and a$ are different variable names.
 
<syntaxhighlight lang="m2000 interpreter">
a="ok"
a+="(one)"
Print a
 
a$="ok"
a$+="(one)"
Line 1,195 ⟶ 1,364:
<pre>
foobar
</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
s1 = "Hello"
s1 = s1 + ", "
s1 += "World!"
print s1
</syntaxhighlight>
{{out}}
<pre>
Hello, World!
</pre>
 
Line 1,536 ⟶ 1,717:
end
</syntaxhighlight>
 
=={{header|RPL}}==
In HP-48+ RPL versions, the <code>STO+</code> instruction can append a string to a variable containing already a string.
"def" '<span style="color:green">Z</span>' STO
'<span style="color:green">Z</span>' "ghi" STO+
<span style="color:green">Z</span>
'''Output'''
<span style="color:grey"> 1:</span> "defghi"
 
=={{header|Ruby}}==
Line 1,716 ⟶ 1,905:
 
=={{header|Wren}}==
<syntaxhighlight lang="javascriptwren">var s = "Hello, "
s = s + "world!"
System.print(s)</syntaxhighlight>
56

edits