String append: Difference between revisions

10,414 bytes added ,  2 months ago
m
 
(28 intermediate revisions by 21 users not shown)
Line 18:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V s = ‘12345678’
s ‘’= ‘9!’
print(s)</langsyntaxhighlight>
 
{{out}}
Line 29:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<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>
</lang>
{{Output}}
<pre>
Line 126:
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">
<lang Action!>
CHAR ARRAY S1,S2
 
Line 135:
Print(S1)
Return
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 143:
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;
Line 153:
Put_Line(Str);
end String_Append;
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 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'''<langsyntaxhighlight lang="algol68">#!/usr/bin/a68g --script #
# -*- coding: utf-8 -*- #
 
STRING str := "12345678";
str +:= "9!";
print(str)</langsyntaxhighlight>
{{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">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program appendstr.s */
Line 274 ⟶ 294:
 
 
</syntaxhighlight>
</lang>
 
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">
<lang AppleScript>
set {a, b} to {"Apple", "Script"}
set a to a & b
return a as string
</syntaxhighlight>
</lang>
 
{{out}}
Line 289 ⟶ 309:
 
=={{header|APL}}==
<langsyntaxhighlight APLlang="apl"> s←'hello'
s,'world'
helloworld</langsyntaxhighlight>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">print join ["Hello" "World"]
 
a: new "Hello"
Line 305 ⟶ 325:
 
c: "Hello"
print append c "World"</langsyntaxhighlight>
 
{{out}}
Line 315 ⟶ 335:
 
=={{header|Asymptote}}==
<langsyntaxhighlight Asymptotelang="asymptote">string s = "Hello";
s = s + " Wo";
s += "rld!";
write(s);</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">s := "Hello, "
s .= "world."
MsgBox % s</langsyntaxhighlight>
{{out}}<pre>Hello, world.</pre>
 
Line 329 ⟶ 349:
Avail's normal strings are immutable, however string ''variables'' can leverage tuple's appending-assignment method, <code>_↑++=_</code>.
 
<langsyntaxhighlight Availlang="avail">str : string := "99 bottles of ";
str ++= "beer";
Print: str;</langsyntaxhighlight>
 
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:
 
<langsyntaxhighlight Availlang="avail">Public method "_↑++=_" is
[
var : read tuple/write ⊥,
Line 341 ⟶ 361:
|
var ?= eject var ++ t;
] : ⊤;</langsyntaxhighlight>
(<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">
<lang AWK>
# syntax: GAWK -f STRING_APPEND.AWK
BEGIN {
Line 353 ⟶ 373:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 360 ⟶ 380:
 
=={{header|Axe}}==
<langsyntaxhighlight lang="axe">Lbl STRCAT
Copy(r₂,r₁+length(r₁),length(r₂)+1)
r₁
Return</langsyntaxhighlight>
 
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight BASIClang="basic">S$ = "Hello"
S$ = S$ + " World!"
PRINT S$</langsyntaxhighlight>
 
==={{header|BaCon}}===
<langsyntaxhighlight lang="freebasic">
A$ = "Hello"
A$ = A$ & " World!"
PRINT A$
</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">a$ = "He"
a$ = a$ & "llo"
a$ = a$ + " Wo"
a$ += "rld"
a$ &= "!"
print a$</syntaxhighlight>
 
==={{header|BBC BASIC}}===
<langsyntaxhighlight BBClang="bbc BASICbasic"> S$="Hello"
S$+=" World!"
PRINT S$
END</langsyntaxhighlight>
{{out}}
<pre>Hello World!</pre>
 
==={{header|Commodore BASIC}}===
<langsyntaxhighlight GWBASIClang="gwbasic">10 S$ = "HELLO"
20 S$ = S$ + " WORLD!"
30 PRINT S$
40 END</langsyntaxhighlight>
{{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}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 LET S$="Hello"
110 LET S$=S$&" World!"
120 PRINT S$</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<lang freebasic>a$ = "He"
a$ = a$ & "llo"
a$ = a$ + " Wo"
a$ += "rld"
a$ &= "!"
print a$</lang>
 
==={{header|Liberty BASIC}}===
<langsyntaxhighlight lang="lb">a$ = "Hello"
a$ = a$ + " World"
a$ = a$ ; "!"
print a$</langsyntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|QBasic}}===
Line 421 ⟶ 459:
{{works with|Run BASIC}}
{{works with|Yabasic}}
<langsyntaxhighlight QBasiclang="qbasic">a$ = "Hello"
a$ = a$ + " World!"
PRINT a$</langsyntaxhighlight>
 
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Run BASIC}}===
Line 430 ⟶ 471:
{{works with|QBasic}}
{{works with|Yabasic}}
<langsyntaxhighlight lang="runbasic">a$ = "Hello"
a$ = a$ + " World!"
print a$</langsyntaxhighlight>
 
==={{header|True BASIC}}===
<langsyntaxhighlight lang="qbasic">LET a$ = "Hello"
LET a$ = a$ & " World!"
PRINT a$
END</langsyntaxhighlight>
 
==={{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 445 ⟶ 505:
{{works with|QBasic}}
{{works with|Run BASIC}}
<langsyntaxhighlight lang="yabasic">a$ = "Hello"
a$ = a$ + " World!"
print a$</langsyntaxhighlight>
 
 
=={{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}}==
<langsyntaxhighlight Bracmatlang="bracmat">str="Hello";
str$(!str " World!"):?str;
out$!str;</langsyntaxhighlight>
{{out}}
<pre>Hello World!</pre>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include<stdio.h>
#include<string.h>
 
Line 482 ⟶ 558:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Good Morning to all !!!</pre>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">class Program
{
static void Main(string[] args)
Line 495 ⟶ 571:
System.Console.WriteLine(x);
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <string>
 
Line 506 ⟶ 582:
std::cout << greeting << std::endl ;
return 0 ;
}</langsyntaxhighlight>
{{out}}
<pre>Hello , world!</pre>
Line 512 ⟶ 588:
=={{header|Clojure}}==
Using global vars.
<langsyntaxhighlight lang="clojure">user=> (def s "app")
#'user/s
user=> s
Line 519 ⟶ 595:
#'user/s
user=> s
"append"</langsyntaxhighlight>
 
Using local bindings.
<langsyntaxhighlight lang="clojure">
user=> (let [s "ap", s (str s "pend")] s)
"append"</langsyntaxhighlight>
 
=={{header|COBOL}}==
Line 532 ⟶ 608:
 
{{works with|GnuCOBOL}}
<langsyntaxhighlight COBOLlang="cobol"> identification division.
program-id. string-append.
 
Line 555 ⟶ 631:
goback.
end program string-append.
</syntaxhighlight>
</lang>
{{out}}
<pre>$ cobc -xj string-append.cob
Line 562 ⟶ 638:
=={{header|CoffeeScript}}==
{{works with|Node.js}}
<langsyntaxhighlight lang="coffeescript">a = "Hello, "
b = "World!"
c = a + b
 
console.log c</langsyntaxhighlight>
Or with concat:
<langsyntaxhighlight lang="coffeescript">console.log "Hello, ".concat "World!"</langsyntaxhighlight>
{{out}}
<pre>Hello, World!</pre>
Line 574 ⟶ 650:
=={{header|Common Lisp}}==
Similar to the [[String append#Racket| Racket]] solution, a macro is necessary to append in-place:
<langsyntaxhighlight lang="lisp">(defmacro concatenatef (s &rest strs)
"Append additional strings to the first string in-place."
`(setf ,s (concatenate 'string ,s ,@strs)))
Line 581 ⟶ 657:
(format T "~a~%" *str*)
(concatenatef *str* "baz" "abc" "def")
(format T "~a~%" *str*)</langsyntaxhighlight>
 
Output:
Line 588 ⟶ 664:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio;
 
void main() {
Line 594 ⟶ 670:
s ~= " world!";
writeln(s);
}</langsyntaxhighlight>
{{out}}
<pre>Hello world!</pre>
 
=={{header|Dart}}==
<syntaxhighlight lang="dart">void main() {
String str = "Hello";
str = str + " World!";
print(str);
}</syntaxhighlight>
 
=={{header|DBL}}==
<langsyntaxhighlight DBLlang="dbl">;Concatenate "Hello world!"
STR='Hello'
STR(%TRIM(STR)+2:5)='world'
STR(%TRIM(STR)+1:1)='!'</langsyntaxhighlight>
 
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program String_append;
 
Line 645 ⟶ 727:
writeln(h);
readln;
end.</langsyntaxhighlight>
{{out}}
<pre>Hello World
Line 653 ⟶ 735:
 
=={{header|Dyalect}}==
<langsyntaxhighlight lang="dyalect">var str = "foo"
str += str
print(str)</langsyntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">a$ = "hello"
a$ &= " world"
print a$</langsyntaxhighlight>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="lisp">
;; Solution from Common Lisp and Racket
(define-syntax-rule (set-append! str tail)
Line 673 ⟶ 755:
name
→ "Albert de Jeumont-Schneidre"
</syntaxhighlight>
</lang>
 
=={{header|Elena}}==
ELENA 46.x :
<langsyntaxhighlight lang="elena">import extensions'text;
import extensions'text;
 
public program()
{
var s := StringWriter.load("Hello");
s.append:(" World");
console.printLine:writeLine(s).readChar()
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">iex(60)> s = "Hello"
"Hello"
iex(61)> s <> " World!"
"Hello World!"</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
Line 698 ⟶ 779:
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:
 
<langsyntaxhighlight Lisplang="lisp">(defvar str "foo")
(setq str (concat str "bar"))
str ;=> "foobar"</langsyntaxhighlight>
 
This can be hidden by using a macro such as <code>cl-callf</code> which expands into the above code:
 
{{libheader|cl-lib}}
<langsyntaxhighlight Lisplang="lisp">(require 'cl-lib)
 
(defvar str "foo")
(cl-callf concat str "bar")
str ;=> "foobar"</langsyntaxhighlight>
 
Buffers can be thought of as expandable strings:
 
<langsyntaxhighlight Lisplang="lisp">(let ((buf (get-buffer-create "*foo*")))
(with-current-buffer buf
(insert "foo"))
Line 720 ⟶ 801:
(insert "bar")
(buffer-string)))
;; => "foobar"</langsyntaxhighlight>
 
=={{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 732 ⟶ 827:
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang="euphoria">
sequence string = "String"
 
Line 740 ⟶ 835:
 
printf(1,"%s",{string})
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 749 ⟶ 844:
=={{header|F_Sharp|F#}}==
Strings are immutable in .NET. To append (to the same variable) the variable has to be declared mutable.
<langsyntaxhighlight lang="fsharp">let mutable x = "foo"
x <- x + "bar"
printfn "%s" x</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">"Hello, " "world!" append</langsyntaxhighlight>
{{out}}
<pre>
Line 761 ⟶ 856:
 
=={{header|Falcon}}==
<langsyntaxhighlight lang="falcon">
/* Added by Aykayayciti Earl Lamont Montgomery
April 10th, 2018 */
Line 768 ⟶ 863:
> s1 + " World"
printl(s2 + " bar")
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 777 ⟶ 872:
 
=={{header|Forth}}==
<langsyntaxhighlight Forthlang="forth">\ Strings in Forth are simply named memory locations
 
create astring 256 allot \ create a "string"
Line 783 ⟶ 878:
s" Hello " astring PLACE \ initialize the string
 
s" World!" astring +PLACE \ append with "+place"</langsyntaxhighlight>
 
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>
</lang>
 
=={{header|Fortran}}==
Line 797 ⟶ 892:
'''Using deferred length character strings:'''
 
<syntaxhighlight lang="fortran">
<lang Fortran>
program main
 
Line 808 ⟶ 903:
 
end program main
</syntaxhighlight>
</lang>
 
{{out}}
Line 816 ⟶ 911:
'''Using pre-allocated character strings:'''
 
<syntaxhighlight lang="fortran">
<lang Fortran>
program str_append
implicit none
Line 827 ⟶ 922:
 
end program str_append
</syntaxhighlight>
</lang>
 
{{out}}
Line 833 ⟶ 928:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Var s = "String"
s += " append"
Print s
Sleep</langsyntaxhighlight>
 
{{out}}
Line 844 ⟶ 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]'''
<langsyntaxhighlight lang="gambas">Public Sub Main()
Dim sString As String = "Hello "
 
Line 853 ⟶ 960:
Print sString
 
End</langsyntaxhighlight>
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}}==
<langsyntaxhighlight lang="genie">[indent=4]
/* String append, in Genie */
init
Line 866 ⟶ 992:
str += ", world"
 
print str</langsyntaxhighlight>
{{out}}
<pre>prompt$ valac stringAppend.gs
Line 873 ⟶ 999:
 
=={{header|GlovePIE}}==
<langsyntaxhighlight lang="glovepie">var.string="This is "
var.string+="Sparta!"
debug=var.string</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">s := "foo"
s += "bar"</langsyntaxhighlight>
 
=== 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">
<lang go>
package main
 
Line 897 ⟶ 1,023:
fmt.Print(s.String())
}
</syntaxhighlight>
</lang>
{{out}}
foobar
 
=={{header|Gosu}}==
<langsyntaxhighlight lang="gosu">// Example 1
var s = "a"
s += "b"
Line 915 ⟶ 1,041:
var b = "b"
var c = "c"
print("${a}${b}${c}")</langsyntaxhighlight>
{{out}}
<pre>
Line 924 ⟶ 1,050:
 
=={{header|Groovy}}==
<syntaxhighlight lang="groovy">
<lang Groovy>
class Append{
static void main(String[] args){
Line 933 ⟶ 1,059:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 941 ⟶ 1,067:
=={{header|Haskell}}==
 
<langsyntaxhighlight lang="haskell">
main = putStrLn ("Hello" ++ "World")
</syntaxhighlight>
</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
In both languages you can:
 
<langsyntaxhighlight lang="unicon">
procedure main()
s := "foo"
Line 954 ⟶ 1,080:
write(s)
end
</syntaxhighlight>
</lang>
 
Outputs:
Line 965 ⟶ 1,091:
 
=={{header|J}}==
<langsyntaxhighlight lang="j"> s=: 'new'
s
new
s=: s,' value' NB. append is in-place
s
new value</langsyntaxhighlight>
 
=={{header|Java}}==
There are multiple ways to append string values in Java.<br />
<lang Java>String sa = "Hello";
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 980 ⟶ 1,145:
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());</langsyntaxhighlight>
{{out}}
<pre>
Line 990 ⟶ 1,155:
{{works with|Rhino}}
{{works with|SpiderMonkey}}
<langsyntaxhighlight JavaScriptlang="javascript">var s1 = "Hello";
s1 += ", World!";
print(s1);
Line 997 ⟶ 1,162:
// concat() returns the strings together, but doesn't edit existing string
// concat can also have multiple parameters
print(s2.concat(", World!"));</langsyntaxhighlight>
{{out}}
<pre>
Line 1,005 ⟶ 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:<langsyntaxhighlight lang="jq">"Hello" | . += ", world!"
 
["Hello"] | .[0] += ", world!" | .[0]
 
{ "greeting": "Hello"} | .greeting += ", world!" | .greeting</langsyntaxhighlight>
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:<langsyntaxhighlight lang="jq">"Hello" as $a | $a | . += ", world!" as $a | $a</langsyntaxhighlight>
 
=={{header|Jsish}}==
From Javascript entry.
<langsyntaxhighlight lang="javascript">/* String append, in Jsish */
var str = 'Hello';
;str += ', world';
Line 1,026 ⟶ 1,191:
s2.concat(', World!') ==> Goodbye, World!
=!EXPECTEND!=
*/</langsyntaxhighlight>
 
{{out}}
Line 1,034 ⟶ 1,199:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">s = "Hello"
s *= ", world!"</langsyntaxhighlight>
{{out}}
<pre>"Hello, world!"</pre>
 
=={{header|K}}==
<syntaxhighlight lang=K>h: "hello "
h,: "world"
h
"hello world"</syntaxhighlight>
=={{header|Kotlin}}==
<langsyntaxhighlight lang="kotlin">fun main(args: Array<String>) {
var s = "a"
s += "b"
Line 1,050 ⟶ 1,220:
val c = "c"
println("$a$b$c")
}</langsyntaxhighlight>
{{out}}
<pre>abc
Line 1,058 ⟶ 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">
<lang Scheme>
{def christian_name Albert}
-> christian_name
Line 1,066 ⟶ 1,236:
{christian_name} {name}
-> Albert de Jeumont-Schneidre
</syntaxhighlight>
</lang>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
$s = Hello
$s += \, World!
 
fn.println($s)
</syntaxhighlight>
{{out}}
<pre>
Hello World
</pre>
 
=={{header|langur}}==
<langsyntaxhighlight lang="langur">var .s = "no more "
.s ~= "foo bars"
writeln .s</langsyntaxhighlight>
 
{{out}}
Line 1,077 ⟶ 1,259:
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">local(x = 'Hello')
#x->append(', World!')
#x</langsyntaxhighlight>
{{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}}==
<langsyntaxhighlight lang="lingo">str = "Hello"
put " world!" after str
put str
-- "Hello world!"</langsyntaxhighlight>
 
=={{header|LiveCode}}==
Livecode has an "after" keyword for this
<langsyntaxhighlight LiveCodelang="livecode">local str="live"
put "code" after str</langsyntaxhighlight>
Output is "livecode"
 
=={{header|Lua}}==
Not possible as strings are immutable. We can demonstrate their immutability using 'self':
<langsyntaxhighlight Lualang="lua">function string:show ()
print(self)
end
Line 1,108 ⟶ 1,304:
x:show()
x:append("there!")
x:show()</langsyntaxhighlight>
{{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:
<langsyntaxhighlight Lualang="lua">x = "Hi "
x = x .. "there!"
print(x)</langsyntaxhighlight>
{{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
 
<lang M2000 Interpreter>
a$="ok"
a$+="(one)"
Line 1,131 ⟶ 1,331:
b$="(one)"
Print b$
</syntaxhighlight>
</lang>
{{out}}
<pre>ok(one)
Line 1,138 ⟶ 1,338:
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">a := "Hello";
b := cat(a, " World");
c := `||`(a, " World");</langsyntaxhighlight>
{{out}}
<pre>
Line 1,149 ⟶ 1,349:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">(* mutable strings are not supported *)
s1 = "testing";
s1 = s1 <> " 123";
s1</langsyntaxhighlight>
{{out}}
<pre>"testing 123"</pre>
Line 1,158 ⟶ 1,358:
=={{header|min}}==
{{works with|min|0.19.6}}
<langsyntaxhighlight lang="min">(quote cons "" join) :str-append
 
"foo" "bar" str-append puts!</langsyntaxhighlight>
{{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}}==
<langsyntaxhighlight MontiLanglang="montilang">|Hello | |world!| swap + print</langsyntaxhighlight>
<langsyntaxhighlight MontiLanglang="montilang">|Hello | var hello .
|world!| var world .
world hello + print</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">s1 = "this is"
s1 += " a test"
 
println s1</langsyntaxhighlight>
 
{{out}}
Line 1,184 ⟶ 1,396:
The plus operator +, concats strings.
<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
<doc><p>String append in Neko</pre></doc>
**/
Line 1,190 ⟶ 1,402:
var str = "Hello"
str += ", world"
$print(str, "\n")</langsyntaxhighlight>
{{out}}
<pre>prompt$ nekoc string-append.neko
Line 1,197 ⟶ 1,409:
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">s_ = 'Hello'
s_ = s_', world!'
say s_</langsyntaxhighlight>
{{out}}
<pre>
Line 1,206 ⟶ 1,418:
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">(setq str "foo")
 
(push "bar" str -1)
Line 1,213 ⟶ 1,425:
 
(println str)
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">var str = "123456"
str.add("78") # Using procedure "add".
str &= "9!" # Using operator "&=".
echo str
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,226 ⟶ 1,438:
 
=={{header|NS-HUBASIC}}==
<langsyntaxhighlight NSlang="ns-HUBASIChubasic">10 S$ = "HELLO"
20 S$ = S$ + " WORLD!"
30 PRINT S$</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
class Append {
function : Main(args : String[]) ~ Nil {
Line 1,239 ⟶ 1,451:
}
}
</syntaxhighlight>
</lang>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">let () =
let s = Buffer.create 17 in
Buffer.add_string s "Bonjour";
Buffer.add_string s " tout le monde!";
print_endline (Buffer.contents s)</langsyntaxhighlight>
{{out}}
<pre>Bonjour tout le monde!</pre>
Line 1,252 ⟶ 1,464:
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">StringBuffer new "Hello, " << "World!" << println</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
Not supported in GP.
<langsyntaxhighlight lang="parigp">s = "Hello";
s = Str(s, ", world!")</langsyntaxhighlight>
{{out}}
<pre>%1 = "Hello, world!"</pre>
Line 1,265 ⟶ 1,477:
{{works with|Free Pascal|2.6.2}}
 
<langsyntaxhighlight Pascallang="pascal">program StringAppend;
{$mode objfpc}{$H+}
 
Line 1,281 ⟶ 1,493:
WriteLn(S);
ReadLn;
end.</langsyntaxhighlight>
Output:
<pre>Hello World !</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">my $str = 'Foo';
$str .= 'bar';
print $str;</langsyntaxhighlight>
{{out}}
<pre>Foobar</pre>
Line 1,294 ⟶ 1,506:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<langsyntaxhighlight Phixlang="phix">-->
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,303 ⟶ 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}}==
<langsyntaxhighlight lang="picolisp">(setq Str1 "12345678")
(setq Str1 (pack Str1 "9!"))
(println Str1)</langsyntaxhighlight>
{{out}}
<pre>"123456789!"</pre>
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">
<lang Pike>
string msg = "hello";
msg += " world";
write(msg +"\n");
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,323 ⟶ 1,557:
 
=={{header|PL/I}}==
<langsyntaxhighlight PLlang="pl/Ii">Cat: procedure options (main);
declare s character (100) varying;
s = 'dust ';
s ||= 'bowl';
put (s);
end Cat;</langsyntaxhighlight>
<pre>dust bowl</pre>
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Put "abc" into a string.
Line 1,338 ⟶ 1,572:
Write the string to the console.
Wait for the escape key.
Shut down.</langsyntaxhighlight>
{{out}}
<pre>
Line 1,346 ⟶ 1,580:
=={{header|plainTeX}}==
Works with any TeX engine
<langsyntaxhighlight lang="tex">\def\addtomacro#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\def\foo{Hello}
Initial: \foo
Line 1,352 ⟶ 1,586:
\addtomacro\foo{ world!}
Appended: \foo
\bye</langsyntaxhighlight>
 
pdf or dvi output:
Line 1,360 ⟶ 1,594:
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
$str = "Hello, "
$str += "World!"
$str
</syntaxhighlight>
</lang>
<pre>Hello, World!</pre>
 
=={{header|PureBasic}}==
<langsyntaxhighlight lang="purebasic">S$ = "Hello"
S$ = S$ + " Wo" ;by referencing the string twice
S$ + "rld!" ;by referencing the string once
Line 1,376 ⟶ 1,610:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
Sample output:
<pre>Hello World!</pre>
 
=={{header|Python}}==
'''File: String_append.py'''<langsyntaxhighlight lang="python">#!/usr/bin/env python
# -*- coding: utf-8 -*- #
 
str = "12345678";
str += "9!";
print(str)</langsyntaxhighlight>
{{out}}
<pre>
Line 1,393 ⟶ 1,627:
 
=={{header|QB64}}==
<langsyntaxhighlight lang="qbasic">s$ = "String"
s$ = s$ + " append"
Print s$</langsyntaxhighlight>
{{out}}
<pre>String append</pre>
Line 1,403 ⟶ 1,637:
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>.
 
<langsyntaxhighlight Quackerylang="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$ </langsyntaxhighlight>
 
{{out}}
Line 1,414 ⟶ 1,648:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">;there is no built-in way to set! append in racket
(define mystr "foo")
(set! mystr (string-append mystr " bar"))
Line 1,425 ⟶ 1,659:
(define mymacrostr "foo")
(set-append! mymacrostr " bar")
(displayln mystr)</langsyntaxhighlight>
 
{{out}}
Line 1,435 ⟶ 1,669:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my $str = "foo";
$str ~= "bar";
say $str;</langsyntaxhighlight>
{{out}}
<pre>foobar</pre>
 
=={{header|Relation}}==
<syntaxhighlight lang="relation">
<lang Relation>
set a = "Hello"
set b = " World"
set c = a.b
echo c
</syntaxhighlight>
</lang>
 
=={{header|REXX}}==
===using abutment===
<langsyntaxhighlight lang="rexx">s='he'
s=s'llo world!'
Say s</langsyntaxhighlight>
'''output'''
<pre>
Line 1,460 ⟶ 1,694:
 
===using concatenation===
<langsyntaxhighlight lang="rexx">s="He"
s=s || 'llo, World!' /*same as: s=s||'llo, World!' */
say s</langsyntaxhighlight>
'''output'''
<pre>
Line 1,469 ⟶ 1,703:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
aString1 = "Welcome to the "
aString2 = "Ring Programming Language"
aString3 = aString1 + aString2
see aString3
</syntaxhighlight>
</lang>
 
=={{header|Robotic}}==
<langsyntaxhighlight lang="robotic">
set "$str1" to "Hello "
inc "$str1" by "world!"
* "&$str1&"
end
</syntaxhighlight>
</lang>
 
=={{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}}==
<langsyntaxhighlight lang="ruby">s = "Hello wo"
s += "rld" # new string object
s << "!" # mutates in place, same object
puts s</langsyntaxhighlight>
{{out}}<pre>Hello world!</pre>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
use std::ops::Add;
 
Line 1,498 ⟶ 1,740:
let hello = String::from("Hello world");
println!("{}", hello.add("!!!!"));
}</langsyntaxhighlight>
{{out}}
Hello world!!!!
Line 1,504 ⟶ 1,746:
=== Real append ===
The first solution doesn't append to the string variable. This solution really appends to the existing variable.
<langsyntaxhighlight lang="rust">
fn main(){
let mut hello = String::from("Hello world");
Line 1,510 ⟶ 1,752:
println!("{}", hello);
}
</syntaxhighlight>
</lang>
{{out}}
Hello world!!!!
Line 1,516 ⟶ 1,758:
=={{header|Scala}}==
An evaluation in Scala worksheet.
<langsyntaxhighlight lang="scala"> var d = "Hello" // Mutables are discouraged //> d : String = Hello
d += ", World!" // var contains a totally new re-instantiationed String
 
Line 1,523 ⟶ 1,765:
val f2 = () => " !" //Function assigned to variable
//> f2 : () => String = <function0>
println(s1 + f2()); //> HelloHello !</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 1,534 ⟶ 1,791:
str &:= "9!";
writeln(str);
end func;</langsyntaxhighlight>
 
{{out}}
Line 1,542 ⟶ 1,799:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var str = 'Foo';
str += 'bar';
say str;</langsyntaxhighlight>
{{out}}
<pre>Foobar</pre>
 
=={{header|SNOBOL4}}==
<langsyntaxhighlight SNOBOL4lang="snobol4"> s = "Hello"
s = s ", World!"
OUTPUT = s
END</langsyntaxhighlight>
{{out}}
<pre>Hello, World!</pre>
 
=={{header|Stata}}==
<langsyntaxhighlight lang="stata">sca s="Ars Longa"
sca s=s+" Vita Brevis"
di s
 
Ars Longa Vita Brevis</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">var s = "foo" // "foo"
s += "bar" // "foobar"
print(s) // "foobar"
s.appendContentsOf("baz") // "foobarbaz"
print(s) // "foobarbaz"</langsyntaxhighlight>
 
=={{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:
<langsyntaxhighlight lang="tcl">set s "he"
set s "${s}llo wo"; # The braces distinguish varname from text to concatenate
append s "rld"
puts $s</langsyntaxhighlight>
{{out}}<pre>hello world</pre>
 
=={{header|Transd}}==
<langsyntaxhighlight Schemelang="scheme">#lang transd
 
MainModule: {
Line 1,587 ⟶ 1,844:
(textout s1))
)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,594 ⟶ 1,851:
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">decl string str
set str "hello "
 
Line 1,601 ⟶ 1,858:
 
# outputs "hello world"
out str endl console</langsyntaxhighlight>
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">void main() {
string x = "foo";
x += "bar\n";
print(x);
}</langsyntaxhighlight>
 
=={{header|VBA}}==
<langsyntaxhighlight VBlang="vb">Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function</langsyntaxhighlight>
 
=={{header|VBScript}}==
<langsyntaxhighlight lang="vb">s = "Rosetta"
s = s & " Code"
WScript.StdOut.Write s</langsyntaxhighlight>
{{out}}
<pre>Rosetta Code</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">mut s:= 'foo'
s += 'bar'
println(s)
Line 1,633 ⟶ 1,890:
bar := 'bar'
foobar := '$foo$bar'
println(foobar)</langsyntaxhighlight>
 
{{out}}
Line 1,644 ⟶ 1,901:
 
=={{header|Wart}}==
<langsyntaxhighlight lang="python">s <- "12345678"
s <- (s + "9!")</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight javascriptlang="wren">var s = "Hello, "
s = s + "world!"
System.print(s)</langsyntaxhighlight>
 
{{out}}
Line 1,658 ⟶ 1,915:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include xpllib;
char A, B, C(80);
[A:= "Hello, ";
Line 1,665 ⟶ 1,922:
StrCat(C, B);
Text(0, C);
]</langsyntaxhighlight>
 
{{out}}
Line 1,674 ⟶ 1,931:
=={{header|zkl}}==
zkl strings are immutable, but byte blobs are mutable.
<langsyntaxhighlight lang="zkl">var s="foo";
s.append("bar"); //-->new string "foobar", var s unchanged
s+="bar"; //-->new string "foobar", var s modifed to new value
Line 1,680 ⟶ 1,937:
s=Data(Void,"foo"); // byte blob/character blob/text editor buffer
s.append("bar"); // or s+="bar"
s.text; //-->"foobar"</langsyntaxhighlight>
 
{{omit from|bc|No string operations in bc}}
56

edits