String append: Difference between revisions
m
→{{header|Binary Lambda Calculus}}
(49 intermediate revisions by 34 users not shown) | |||
Line 18:
{{trans|Python}}
<
s ‘’= ‘9!’
print(s)</
{{out}}
Line 29:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program appendstr64.s */
Line 116:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
{{Output}}
<pre>
Line 124:
Alphabet : abcdefghijklmnopqrstuvwxyz
</pre>
=={{header|Action!}}==
<syntaxhighlight lang="action!">
CHAR ARRAY S1,S2
Proc Main()
S1="Hello, "
S2="world!";
Sassign(S1,S2,S1(0)+1)
Print(S1)
Return
</syntaxhighlight>
{{out}}
<pre>
Hello, world!
</pre>
=={{header|Ada}}==
<
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;
Line 136 ⟶ 153:
Put_Line(Str);
end String_Append;
</syntaxhighlight>
{{out}}
<pre>
Line 146 ⟶ 163:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.7 algol68g-2.7].}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards).}}
'''File: String_append.a68'''<
# -*- coding: utf-8 -*- #
STRING str := "12345678";
str +:= "9!";
print(str)</
{{out}}
<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>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program appendstr.s */
Line 257 ⟶ 294:
</syntaxhighlight>
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">
set {a, b} to {"Apple", "Script"}
set a to a & b
return a as string
</syntaxhighlight>
{{out}}
<pre>
"AppleScript"
</pre>
=={{header|APL}}==
<syntaxhighlight lang="apl"> s←'hello'
s,'world'
helloworld</syntaxhighlight>
=={{header|Arturo}}==
<
a: new "Hello"
'a ++ "World"
print a
b: new "Hello"
append 'b "World"
print b
c: "Hello"
print append c "World"</
{{out}}
Line 279 ⟶ 333:
HelloWorld
HelloWorld</pre>
=={{header|Asymptote}}==
<syntaxhighlight lang="asymptote">string s = "Hello";
s = s + " Wo";
s += "rld!";
write(s);</syntaxhighlight>
=={{header|AutoHotkey}}==
<
s .= "world."
MsgBox % s</
{{out}}<pre>Hello, world.</pre>
Line 289 ⟶ 349:
Avail's normal strings are immutable, however string ''variables'' can leverage tuple's appending-assignment method, <code>_↑++=_</code>.
<
str ++= "beer";
Print: str;</
Note that one can define methods similar to this, thanks to the ''variable occurrence'' message pattern, <code>_↑</code>, whose slot accepts a variable usage and then passes the variable container itself as the corresponding argument. Consider the source for the append used above:
<
[
var : read tuple/write ⊥,
Line 301 ⟶ 361:
|
var ?= eject var ++ t;
] : ⊤;</
(<code>eject</code> and <code>?=</code> are methods used for unassign-retrieving and assigning to a variable, respectively, only needed when dealing with the containers themselves.)
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f STRING_APPEND.AWK
BEGIN {
Line 313 ⟶ 373:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 320 ⟶ 380:
=={{header|Axe}}==
<
Copy(r₂,r₁+length(r₁),length(r₂)+1)
r₁
Return</
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<
S$ = S$ + " World!"
PRINT S$</
==={{header|BaCon}}===
<
A$ = "Hello"
A$ = A$ & " World!"
PRINT A$
</
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">a$ = "He"
a$ = a$ & "llo"
a$ = a$ + " Wo"
a$ += "rld"
a$ &= "!"
print a$</syntaxhighlight>
==={{header|BBC BASIC}}===
<
S$+=" World!"
PRINT S$
END</
{{out}}
<pre>Hello World!</pre>
==={{header|Commodore BASIC}}===
<syntaxhighlight lang="gwbasic">10 S$ = "HELLO"
20 S$ = S$ + " WORLD!"
30 PRINT S$
40 END</syntaxhighlight>
{{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}}===
<
110 LET S$=S$&" World!"
120 PRINT S$</
==={{header|Liberty BASIC}}===
<syntaxhighlight lang="lb">a$ = "Hello"
a$ = a$ + " World"
a$ = a$ ; "!"
print a$</syntaxhighlight>
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
==={{header|QBasic}}===
{{works with|Liberty BASIC}}
{{works with|QB64}}
{{works with|Run BASIC}}
{{works with|Yabasic}}
<syntaxhighlight lang="qbasic">a$ = "Hello"
a$ = a$ + " World!"
PRINT a$</syntaxhighlight>
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
==={{header|Run BASIC}}===
{{works with|Liberty BASIC}}
{{works with|QB64}}
{{works with|QBasic}}
{{works with|Yabasic}}
<syntaxhighlight lang="runbasic">a$ = "Hello"
a$ = a$ + " World!"
print a$</syntaxhighlight>
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">LET a$ = "Hello"
LET a$ = a$ & " World!"
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}}===
{{works with|Liberty BASIC}}
{{works with|QB64}}
{{works with|QBasic}}
{{works with|Run BASIC}}
<syntaxhighlight lang="yabasic">a$ = "Hello"
a$ = a$ + " World!"
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}}==
<
str$(!str " World!"):?str;
out$!str;</
{{out}}
<pre>Hello World!</pre>
=={{header|C}}==
<
#include<string.h>
Line 386 ⟶ 558:
}
return 0;
}</
{{out}}
<pre>Good Morning to all !!!</pre>
=={{header|C sharp|C#}}==
<
{
static void Main(string[] args)
Line 399 ⟶ 571:
System.Console.WriteLine(x);
}
}</
=={{header|C++}}==
<
#include <string>
Line 410 ⟶ 582:
std::cout << greeting << std::endl ;
return 0 ;
}</
{{out}}
<pre>Hello , world!</pre>
Line 416 ⟶ 588:
=={{header|Clojure}}==
Using global vars.
<
#'user/s
user=> s
Line 423 ⟶ 595:
#'user/s
user=> s
"append"</
Using local bindings.
<
user=> (let [s "ap", s (str s "pend")] s)
"append"</
=={{header|COBOL}}==
Line 436 ⟶ 608:
{{works with|GnuCOBOL}}
<
program-id. string-append.
Line 459 ⟶ 631:
goback.
end program string-append.
</syntaxhighlight>
{{out}}
<pre>$ cobc -xj string-append.cob
Line 466 ⟶ 638:
=={{header|CoffeeScript}}==
{{works with|Node.js}}
<
b = "World!"
c = a + b
console.log c</
Or with concat:
<
{{out}}
<pre>Hello, World!</pre>
Line 478 ⟶ 650:
=={{header|Common Lisp}}==
Similar to the [[String append#Racket| Racket]] solution, a macro is necessary to append in-place:
<
"Append additional strings to the first string in-place."
`(setf ,s (concatenate 'string ,s ,@strs)))
Line 485 ⟶ 657:
(format T "~a~%" *str*)
(concatenatef *str* "baz" "abc" "def")
(format T "~a~%" *str*)</
Output:
Line 492 ⟶ 664:
=={{header|D}}==
<
void main() {
Line 498 ⟶ 670:
s ~= " world!";
writeln(s);
}</
{{out}}
<pre>Hello world!</pre>
=={{header|Dart}}==
<syntaxhighlight lang="dart">void main() {
String str = "Hello";
str = str + " World!";
print(str);
}</syntaxhighlight>
=={{header|DBL}}==
<
STR='Hello'
STR(%TRIM(STR)+2:5)='world'
STR(%TRIM(STR)+1:1)='!'</
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
<syntaxhighlight lang="delphi">
program String_append;
Line 549 ⟶ 727:
writeln(h);
readln;
end.</
{{out}}
<pre>Hello World
Line 555 ⟶ 733:
Hello World</pre>
=={{header|Dyalect}}==
<syntaxhighlight lang="dyalect">var str = "foo"
str += str
print(str)</syntaxhighlight>
=={{header|EasyLang}}==
<syntaxhighlight lang="text">a$ = "hello"
a$ &= " world"
print a$</
=={{header|EchoLisp}}==
<
;; Solution from Common Lisp and Racket
(define-syntax-rule (set-append! str tail)
Line 572 ⟶ 755:
name
→ "Albert de Jeumont-Schneidre"
</syntaxhighlight>
=={{header|Elena}}==
ELENA
<
public program()
{
var s := StringWriter.load("Hello");
s.append
console.
}</
=={{header|Elixir}}==
<
"Hello"
iex(61)> s <> " World!"
"Hello World!"</
=={{header|Emacs Lisp}}==
While strings in Emacs Lisp are mutable, they're fixed size. Therefore the <code>concat</code> function creates a new string and the existing string must be referenced twice:
<syntaxhighlight lang="lisp">(defvar str "foo")
(setq str (concat str "bar"))
str ;=> "foobar"</syntaxhighlight>
This can be hidden by using a macro such as <code>cl-callf</code> which expands into the above code:
{{libheader|cl-lib}}
<syntaxhighlight lang="lisp">(require 'cl-lib)
(
(
str ;=> "foobar"</syntaxhighlight>
Buffers can be thought of as expandable strings:
<syntaxhighlight lang="lisp">(let ((buf (get-buffer-create "*foo*")))
(with-current-buffer buf
(insert "foo"))
(with-current-buffer buf
(goto-char (point-max))
(insert "bar")
(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,
</pre>
Line 625 ⟶ 827:
=={{header|Euphoria}}==
<
sequence string = "String"
Line 633 ⟶ 835:
printf(1,"%s",{string})
</syntaxhighlight>
{{out}}
<pre>
Line 642 ⟶ 844:
=={{header|F_Sharp|F#}}==
Strings are immutable in .NET. To append (to the same variable) the variable has to be declared mutable.
<
x <- x + "bar"
printfn "%s" x</
=={{header|Factor}}==
<
{{out}}
<pre>
Line 654 ⟶ 856:
=={{header|Falcon}}==
<
/* Added by Aykayayciti Earl Lamont Montgomery
April 10th, 2018 */
Line 661 ⟶ 863:
> s1 + " World"
printl(s2 + " bar")
</syntaxhighlight>
{{out}}
<pre>
Line 670 ⟶ 872:
=={{header|Forth}}==
<
create astring 256 allot \ create a "string"
Line 676 ⟶ 878:
s" Hello " astring PLACE \ initialize the string
s" World!" astring +PLACE \ append with "+place"</
Test at the console
<syntaxhighlight lang="text"> ok
s" Hello " astring place ok
s" World!" astring +place ok
astring count type Hello World! ok
</syntaxhighlight>
=={{header|Fortran}}==
Line 690 ⟶ 892:
'''Using deferred length character strings:'''
<syntaxhighlight lang="fortran">
program main
Line 701 ⟶ 903:
end program main
</syntaxhighlight>
{{out}}
Line 709 ⟶ 911:
'''Using pre-allocated character strings:'''
<syntaxhighlight lang="fortran">
program str_append
implicit none
Line 720 ⟶ 922:
end program str_append
</syntaxhighlight>
{{out}}
Line 726 ⟶ 928:
=={{header|FreeBASIC}}==
<
Var s = "String"
s += " append"
Print s
Sleep</
{{out}}
Line 737 ⟶ 939:
String append
</pre>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
Str255 s
s = "Hello"
s += " World!"
print s
HandleEvents
</syntaxhighlight>
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=0b17e205d56985c8cd1ff108c6fc9ca4 Click this link to run this code]'''
<
Dim sString As String = "Hello "
Line 746 ⟶ 960:
Print sString
End</
Output:
<pre>
Hello World!
</pre>
=={{header|GDScript}}==
{{works with|Godot|4.0.1}}
<syntaxhighlight lang="gdscript">
extends MainLoop
func _process(_delta: float) -> bool:
var string: String = "123"
string += "abc"
print(string)
return true # Exit
</syntaxhighlight>
{{out}}
<pre>
123abc
</pre>
=={{header|Genie}}==
<
/* String append, in Genie */
init
Line 759 ⟶ 992:
str += ", world"
print str</
{{out}}
<pre>prompt$ valac stringAppend.gs
Line 766 ⟶ 999:
=={{header|GlovePIE}}==
<
var.string+="Sparta!"
debug=var.string</
=={{header|Go}}==
<
s += "bar"</
=== String Builder ===
The first solution redefines the string variable every time. It might be short in code but it uses much CPU cycles. A better way is to use `string.Builder` but it is not a string. It is more like a buffer which can produce a string. And it really appends the string to the existing variable.
<syntaxhighlight lang="go">
package main
Line 790 ⟶ 1,023:
fmt.Print(s.String())
}
</syntaxhighlight>
{{out}}
foobar
=={{header|Gosu}}==
<
var s = "a"
s += "b"
Line 808 ⟶ 1,041:
var b = "b"
var c = "c"
print("${a}${b}${c}")</
{{out}}
<pre>
Line 817 ⟶ 1,050:
=={{header|Groovy}}==
<syntaxhighlight lang="groovy">
class Append{
static void main(String[] args){
Line 826 ⟶ 1,059:
}
}
</syntaxhighlight>
{{out}}
<pre>
Line 834 ⟶ 1,067:
=={{header|Haskell}}==
<
main = putStrLn ("Hello" ++ "World")
</syntaxhighlight>
=={{header|Icon}} and {{header|Unicon}}==
In both languages you can:
<
procedure main()
s := "foo"
Line 847 ⟶ 1,080:
write(s)
end
</syntaxhighlight>
Outputs:
Line 858 ⟶ 1,091:
=={{header|J}}==
<
s
new
s=: s,' value' NB. append is in-place
s
new value</
=={{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!";
System.out.println(sa);
Line 873 ⟶ 1,145:
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());</
{{out}}
<pre>
Line 883 ⟶ 1,155:
{{works with|Rhino}}
{{works with|SpiderMonkey}}
<
s1 += ", World!";
print(s1);
Line 890 ⟶ 1,162:
// concat() returns the strings together, but doesn't edit existing string
// concat can also have multiple parameters
print(s2.concat(", World!"));</
{{out}}
<pre>
Line 898 ⟶ 1,170:
=={{header|jq}}==
jq's <code>+</code> operator can be used to append two strings, and under certain circumstances the <code>+=</code> operator can be used as an abbreviation for appending a string to an existing string. For example, all three of the following produce the same output:<
["Hello"] | .[0] += ", world!" | .[0]
{ "greeting": "Hello"} | .greeting += ", world!" | .greeting</
However the <code>+=</code> operator cannot be used with jq variables in the conventional manner. One could nevertheless use the technique illustrated by the following:<
=={{header|Jsish}}==
From Javascript entry.
<
var str = 'Hello';
;str += ', world';
Line 919 ⟶ 1,191:
s2.concat(', World!') ==> Goodbye, World!
=!EXPECTEND!=
*/</
{{out}}
Line 927 ⟶ 1,199:
=={{header|Julia}}==
<
s *= ", world!"</
{{out}}
<pre>"Hello, world!"</pre>
=={{header|K}}==
<syntaxhighlight lang=K>h: "hello "
h,: "world"
h
"hello world"</syntaxhighlight>
=={{header|Kotlin}}==
<
var s = "a"
s += "b"
Line 943 ⟶ 1,220:
val c = "c"
println("$a$b$c")
}</
{{out}}
<pre>abc
Line 951 ⟶ 1,228:
=={{header|Lambdatalk}}==
In Lambdatalk writing {def name a sequence of words} replaces the sequence of words by the given name in the code string. The name is a word and is not evaluated. Bracketing a name between two curly braces returns its related value. And concatenating named strings is simply done by writing names between curly braces and separated by spaces.
<syntaxhighlight lang="scheme">
{def christian_name Albert}
-> christian_name
Line 959 ⟶ 1,236:
{christian_name} {name}
-> Albert de Jeumont-Schneidre
</syntaxhighlight>
=={{header|Lang}}==
<syntaxhighlight lang="lang">
$s = Hello
$s += \, World!
fn.println($s)
</syntaxhighlight>
{{out}}
<pre>
Hello World
</pre>
=={{header|langur}}==
<
.s ~= "foo bars"
writeln .s</
{{out}}
Line 970 ⟶ 1,259:
=={{header|Lasso}}==
<
#x->append(', World!')
#x</
{{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}}==
<
put " world!" after str
put str
-- "Hello world!"</
=={{header|LiveCode}}==
Livecode has an "after" keyword for this
<
put "code" after str</
Output is "livecode"
=={{header|Lua}}==
Not possible as strings are immutable. We can demonstrate their immutability using 'self':
<
print(self)
end
Line 1,001 ⟶ 1,304:
x:show()
x:append("there!")
x:show()</
{{out}}
<pre>Hi
Hi </pre>
You can of course concatentate them and store the result in the original variable name but that requires a double reference:
<
x = x .. "there!"
print(x)</
{{out}}
<pre>Hi there!</pre>
=={{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,024 ⟶ 1,331:
b$="(one)"
Print b$
</syntaxhighlight>
{{out}}
<pre>ok(one)
Line 1,031 ⟶ 1,338:
=={{header|Maple}}==
<
b := cat(a, " World");
c := `||`(a, " World");</
{{out}}
<pre>
Line 1,041 ⟶ 1,348:
</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">(* mutable strings are not supported *)
s1 = "testing";
s1 = s1 <> " 123";
s1</
{{out}}
<pre>"testing 123"</pre>
Line 1,052 ⟶ 1,358:
=={{header|min}}==
{{works with|min|0.19.6}}
<
"foo" "bar" str-append puts!</
{{out}}
<pre>
foobar
</pre>
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
s1 = "Hello"
s1 = s1 + ", "
s1 += "World!"
print s1
</syntaxhighlight>
{{out}}
<pre>
Hello, World!
</pre>
=={{header|MontiLang}}==
<
<
|world!| var world .
world hello + print</
=={{header|Nanoquery}}==
<
s1 += " a test"
println s1</
{{out}}
Line 1,078 ⟶ 1,396:
The plus operator +, concats strings.
<syntaxhighlight lang="actionscript">/**
<doc><p>String append in Neko</pre></doc>
**/
Line 1,084 ⟶ 1,402:
var str = "Hello"
str += ", world"
$print(str, "\n")</
{{out}}
<pre>prompt$ nekoc string-append.neko
Line 1,091 ⟶ 1,409:
=={{header|NetRexx}}==
<
s_ = s_', world!'
say s_</
{{out}}
<pre>
Line 1,100 ⟶ 1,418:
=={{header|NewLISP}}==
<
(push "bar" str -1)
Line 1,107 ⟶ 1,425:
(println str)
</syntaxhighlight>
=={{header|Nim}}==
<
str.add("78") # Using procedure "add".
str &= "9!" # Using operator "&=".
echo str
</syntaxhighlight>
{{out}}
Line 1,120 ⟶ 1,438:
=={{header|NS-HUBASIC}}==
<
20 S$ = S$ + " WORLD!"
30 PRINT S$</
=={{header|Objeck}}==
<
class Append {
function : Main(args : String[]) ~ Nil {
Line 1,133 ⟶ 1,451:
}
}
</syntaxhighlight>
=={{header|OCaml}}==
<
let s = Buffer.create 17 in
Buffer.add_string s "Bonjour";
Buffer.add_string s " tout le monde!";
print_endline (Buffer.contents s)</
{{out}}
<pre>Bonjour tout le monde!</pre>
Line 1,146 ⟶ 1,464:
=={{header|Oforth}}==
<
=={{header|PARI/GP}}==
Not supported in GP.
<
s = Str(s, ", world!")</
{{out}}
<pre>%1 = "Hello, world!"</pre>
Line 1,159 ⟶ 1,477:
{{works with|Free Pascal|2.6.2}}
<
{$mode objfpc}{$H+}
Line 1,175 ⟶ 1,493:
WriteLn(S);
ReadLn;
end.</
Output:
<pre>Hello World !</pre>
=={{header|Perl}}==
<
$str .= 'bar';
print $str;</
{{out}}
<pre>Foobar</pre>
Line 1,188 ⟶ 1,506:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"this string"</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">s</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">" is now longer"</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">s</span>
<!--</
{{out}}
<pre>
Line 1,197 ⟶ 1,515:
"this string is now longer"
</pre>
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: https://rosettacode.org/wiki/String_append
by Galileo, 11/2022 #/
"Hello" var s
s " world" chain var s
s print
</syntaxhighlight>
{{out}}
<pre>Hello world
=== Press any key to exit ===</pre>
=={{header|Picat}}==
<syntaxhighlight lang="picat">main =>
S = "a string",
S := S + " that is longer",
println(S).</syntaxhighlight>
{{out}}
<pre>a string that is longer</pre>
=={{header|PicoLisp}}==
<
(setq Str1 (pack Str1 "9!"))
(println Str1)</
{{out}}
<pre>"123456789!"</pre>
=={{header|Pike}}==
<syntaxhighlight lang="pike">
string msg = "hello";
msg += " world";
write(msg +"\n");
</syntaxhighlight>
{{Out}}
<pre>
Line 1,217 ⟶ 1,557:
=={{header|PL/I}}==
<
declare s character (100) varying;
s = 'dust ';
s ||= 'bowl';
put (s);
end Cat;</
<pre>dust bowl</pre>
=={{header|Plain English}}==
<
Start up.
Put "abc" into a string.
Line 1,232 ⟶ 1,572:
Write the string to the console.
Wait for the escape key.
Shut down.</
{{out}}
<pre>
Line 1,240 ⟶ 1,580:
=={{header|plainTeX}}==
Works with any TeX engine
<
\def\foo{Hello}
Initial: \foo
Line 1,246 ⟶ 1,586:
\addtomacro\foo{ world!}
Appended: \foo
\bye</
pdf or dvi output:
Line 1,254 ⟶ 1,594:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
$str = "Hello, "
$str += "World!"
$str
</syntaxhighlight>
<pre>Hello, World!</pre>
=={{header|PureBasic}}==
<
S$ = S$ + " Wo" ;by referencing the string twice
S$ + "rld!" ;by referencing the string once
Line 1,270 ⟶ 1,610:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</
Sample output:
<pre>Hello World!</pre>
=={{header|Python}}==
'''File: String_append.py'''<
# -*- coding: utf-8 -*- #
str = "12345678";
str += "9!";
print(str)</
{{out}}
<pre>
Line 1,287 ⟶ 1,627:
=={{header|QB64}}==
<
s$ = s$ + " append"
Print s$</
{{out}}
<pre>String append</pre>
=={{header|Quackery}}==
Quackery has no variables. The nearest equivalent is ''ancillary stacks''. The word <code>join</code> will return the concatenation of two nests on the stack, and hence two strings, as strings are a particular usage of nests. Here we define the word <code>append</code> to join a nest on the stack to a nest on an ancillary stack, and then demonstrate its use with a Jules Renard quotation and the predefined ancillary stack <code>temp</code>.
<syntaxhighlight lang="quackery"> [ tuck take swap join swap put ] is append ( [ s --> )
$ "L'homme qui attend de voir un canard roti voler " temp put
$ "dans sa bouche doit attendre tres, tres longtemps." temp append
temp take echo$ </syntaxhighlight>
{{out}}
<pre>L'homme qui attend de voir un canard roti voler dans sa bouche doit attendre tres, tres longtemps.</pre>
=={{header|Racket}}==
<
(define mystr "foo")
(set! mystr (string-append mystr " bar"))
Line 1,305 ⟶ 1,659:
(define mymacrostr "foo")
(set-append! mymacrostr " bar")
(displayln mystr)</
{{out}}
Line 1,315 ⟶ 1,669:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
$str ~= "bar";
say $str;</
{{out}}
<pre>foobar</pre>
=={{header|Relation}}==
<syntaxhighlight lang="relation">
set a = "Hello"
set b = " World"
set c = a.b
echo c
</syntaxhighlight>
=={{header|REXX}}==
===using abutment===
<
s=s'llo world!'
Say s</
'''output'''
<pre>
Line 1,340 ⟶ 1,694:
===using concatenation===
<
s=s || 'llo, World!' /*same as: s=s||'llo, World!' */
say s</
'''output'''
<pre>
Line 1,349 ⟶ 1,703:
=={{header|Ring}}==
<
aString1 = "Welcome to the "
aString2 = "Ring Programming Language"
aString3 = aString1 + aString2
see aString3
</syntaxhighlight>
=={{header|Robotic}}==
<
set "$str1" to "Hello "
inc "$str1" by "world!"
* "&$str1&"
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}}==
<
s += "rld" # new string object
s << "!" # mutates in place, same object
puts s</
{{out}}<pre>Hello world!</pre>
=={{header|Rust}}==
<
use std::ops::Add;
Line 1,378 ⟶ 1,740:
let hello = String::from("Hello world");
println!("{}", hello.add("!!!!"));
}</
{{out}}
Hello world!!!!
Line 1,384 ⟶ 1,746:
=== Real append ===
The first solution doesn't append to the string variable. This solution really appends to the existing variable.
<
fn main(){
let mut hello = String::from("Hello world");
Line 1,390 ⟶ 1,752:
println!("{}", hello);
}
</syntaxhighlight>
{{out}}
Hello world!!!!
Line 1,396 ⟶ 1,758:
=={{header|Scala}}==
An evaluation in Scala worksheet.
<
d += ", World!" // var contains a totally new re-instantiationed String
Line 1,403 ⟶ 1,765:
val f2 = () => " !" //Function assigned to variable
//> f2 : () => String = <function0>
println(s1 + f2()); //> HelloHello !</
=={{header|sed}}==
There are no variables in ''sed'', just two distinct locations for storing a string: The "pattern space" and the "hold space".
* The <code>H</code> command appends the content of pattern space to the hold space.
* The <code>G</code> command appends the content of hold space to the pattern space.
* The <code>N</code> command appends the next input line to the pattern space.
All three commands insert a newline character between both strings during appending. In pattern space, it can be removed afterwards with the <code>s</code> command, like this:
<syntaxhighlight lang="sed">N
s/\n//</syntaxhighlight>
* The <code>s</code> command can also be used to append a string literal to the pattern space:
<syntaxhighlight lang="sed">s/$/String Literal/</syntaxhighlight>
* To append further lines to the output (after the printing of the pattern space), the <code>a</code> command is useful:
<syntaxhighlight lang="sed">a\
one more line\
and another one</syntaxhighlight>
=={{header|Seed7}}==
<
const proc: main is func
Line 1,414 ⟶ 1,791:
str &:= "9!";
writeln(str);
end func;</
{{out}}
Line 1,422 ⟶ 1,799:
=={{header|Sidef}}==
<
str += 'bar';
say str;</
{{out}}
<pre>Foobar</pre>
=={{header|SNOBOL4}}==
<
s = s ", World!"
OUTPUT = s
END</
{{out}}
<pre>Hello, World!</pre>
=={{header|Stata}}==
<
sca s=s+" Vita Brevis"
di s
Ars Longa Vita Brevis</
=={{header|Swift}}==
<
s += "bar" // "foobar"
print(s) // "foobar"
s.appendContentsOf("baz") // "foobarbaz"
print(s) // "foobarbaz"</
=={{header|Tcl}}==
String concatenation is a fundamental feature of the Tcl language, and there is also an <code>append</code> that makes concatenation even simpler:
<
set s "${s}llo wo"; # The braces distinguish varname from text to concatenate
append s "rld"
puts $s</
{{out}}<pre>hello world</pre>
=={{header|Transd}}==
<syntaxhighlight lang="scheme">#lang transd
MainModule: {
_start: (λ
(with s1 "aaa" s2 "bbb" s3 "ccc"
(+= s1 s2 s3)
(textout s1))
)
}</syntaxhighlight>
{{out}}
<pre>
aaabbbccc
</pre>
=={{header|Ursa}}==
<
set str "hello "
Line 1,466 ⟶ 1,858:
# outputs "hello world"
out str endl console</
=={{header|Vala}}==
<
string x = "foo";
x += "bar\n";
print(x);
}</
=={{header|VBA}}==
<
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function</
=={{header|VBScript}}==
<
s = s & " Code"
WScript.StdOut.Write s</
{{out}}
<pre>Rosetta Code</pre>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">mut s:= 'foo'
s += 'bar'
println(s)
foo := 'foo'
bar := 'bar'
foobar := '$foo$bar'
println(foobar)</syntaxhighlight>
{{out}}
<pre>foobar
foobar
</pre>
=== String Builder ===
TODO
=={{header|Wart}}==
<
s <- (s + "9!")</
=={{header|Wren}}==
<
s = s + "world!"
System.print(s)</
{{out}}
<pre>
Hello, world!
</pre>
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">include xpllib;
char A, B, C(80);
[A:= "Hello, ";
B:= "world!";
StrCopy(C, A);
StrCat(C, B);
Text(0, C);
]</syntaxhighlight>
{{out}}
Line 1,506 ⟶ 1,931:
=={{header|zkl}}==
zkl strings are immutable, but byte blobs are mutable.
<
s.append("bar"); //-->new string "foobar", var s unchanged
s+="bar"; //-->new string "foobar", var s modifed to new value
Line 1,512 ⟶ 1,937:
s=Data(Void,"foo"); // byte blob/character blob/text editor buffer
s.append("bar"); // or s+="bar"
s.text; //-->"foobar"</
{{omit from|bc|No string operations in bc}}
|