String append: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
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>
Line 176:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program appendstr.s */
Line 274:
 
 
</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:
 
=={{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:
 
c: "Hello"
print append c "World"</langsyntaxhighlight>
 
{{out}}
Line 315:
 
=={{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:
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:
|
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:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 360:
 
=={{header|Axe}}==
<langsyntaxhighlight lang="axe">Lbl STRCAT
Copy(r₂,r₁+length(r₁),length(r₂)+1)
r₁
Return</langsyntaxhighlight>
 
Line 369:
=={{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|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|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 LET S$="Hello"
110 LET S$=S$&" World!"
120 PRINT S$</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<langsyntaxhighlight lang="freebasic">a$ = "He"
a$ = a$ & "llo"
a$ = a$ + " Wo"
a$ += "rld"
a$ &= "!"
print a$</langsyntaxhighlight>
 
==={{header|Liberty BASIC}}===
<langsyntaxhighlight lang="lb">a$ = "Hello"
a$ = a$ + " World"
a$ = a$ ; "!"
print a$</langsyntaxhighlight>
 
==={{header|QBasic}}===
Line 421:
{{works with|Run BASIC}}
{{works with|Yabasic}}
<langsyntaxhighlight QBasiclang="qbasic">a$ = "Hello"
a$ = a$ + " World!"
PRINT a$</langsyntaxhighlight>
 
==={{header|Run BASIC}}===
Line 430:
{{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|Yabasic}}===
Line 445:
{{works with|QBasic}}
{{works with|Run BASIC}}
<langsyntaxhighlight lang="yabasic">a$ = "Hello"
a$ = a$ + " World!"
print a$</langsyntaxhighlight>
 
 
=={{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:
}
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:
System.Console.WriteLine(x);
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <string>
 
Line 506:
std::cout << greeting << std::endl ;
return 0 ;
}</langsyntaxhighlight>
{{out}}
<pre>Hello , world!</pre>
Line 512:
=={{header|Clojure}}==
Using global vars.
<langsyntaxhighlight lang="clojure">user=> (def s "app")
#'user/s
user=> s
Line 519:
#'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:
 
{{works with|GnuCOBOL}}
<langsyntaxhighlight COBOLlang="cobol"> identification division.
program-id. string-append.
 
Line 555:
goback.
end program string-append.
</syntaxhighlight>
</lang>
{{out}}
<pre>$ cobc -xj string-append.cob
Line 562:
=={{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:
=={{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:
(format T "~a~%" *str*)
(concatenatef *str* "baz" "abc" "def")
(format T "~a~%" *str*)</langsyntaxhighlight>
 
Output:
Line 588:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio;
 
void main() {
Line 594:
s ~= " world!";
writeln(s);
}</langsyntaxhighlight>
{{out}}
<pre>Hello world!</pre>
Line 600:
 
=={{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:
writeln(h);
readln;
end.</langsyntaxhighlight>
{{out}}
<pre>Hello World
Line 653:
 
=={{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:
name
→ "Albert de Jeumont-Schneidre"
</syntaxhighlight>
</lang>
 
=={{header|Elena}}==
ELENA 4.x :
<langsyntaxhighlight lang="elena">import extensions;
import extensions'text;
 
Line 686:
console.printLine: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:
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:
(insert "bar")
(buffer-string)))
;; => "foobar"</langsyntaxhighlight>
 
=={{header|Erlang}}==
Line 732:
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang="euphoria">
sequence string = "String"
 
Line 740:
 
printf(1,"%s",{string})
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 749:
=={{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:
 
=={{header|Falcon}}==
<langsyntaxhighlight lang="falcon">
/* Added by Aykayayciti Earl Lamont Montgomery
April 10th, 2018 */
Line 768:
> s1 + " World"
printl(s2 + " bar")
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 777:
 
=={{header|Forth}}==
<langsyntaxhighlight Forthlang="forth">\ Strings in Forth are simply named memory locations
 
create astring 256 allot \ create a "string"
Line 783:
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:
'''Using deferred length character strings:'''
 
<syntaxhighlight lang="fortran">
<lang Fortran>
program main
 
Line 808:
 
end program main
</syntaxhighlight>
</lang>
 
{{out}}
Line 816:
'''Using pre-allocated character strings:'''
 
<syntaxhighlight lang="fortran">
<lang Fortran>
program str_append
implicit none
Line 827:
 
end program str_append
</syntaxhighlight>
</lang>
 
{{out}}
Line 833:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Var s = "String"
s += " append"
Print s
Sleep</langsyntaxhighlight>
 
{{out}}
Line 847:
=={{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:
Print sString
 
End</langsyntaxhighlight>
Output:
<pre>
Line 860:
 
=={{header|Genie}}==
<langsyntaxhighlight lang="genie">[indent=4]
/* String append, in Genie */
init
Line 866:
str += ", world"
 
print str</langsyntaxhighlight>
{{out}}
<pre>prompt$ valac stringAppend.gs
Line 873:
 
=={{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:
fmt.Print(s.String())
}
</syntaxhighlight>
</lang>
{{out}}
foobar
 
=={{header|Gosu}}==
<langsyntaxhighlight lang="gosu">// Example 1
var s = "a"
s += "b"
Line 915:
var b = "b"
var c = "c"
print("${a}${b}${c}")</langsyntaxhighlight>
{{out}}
<pre>
Line 924:
 
=={{header|Groovy}}==
<syntaxhighlight lang="groovy">
<lang Groovy>
class Append{
static void main(String[] args){
Line 933:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 941:
=={{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:
write(s)
end
</syntaxhighlight>
</lang>
 
Outputs:
Line 965:
 
=={{header|J}}==
<langsyntaxhighlight lang="j"> s=: 'new'
s
new
s=: s,' value' NB. append is in-place
s
new value</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight Javalang="java">String sa = "Hello";
sa += ", World!";
System.out.println(sa);
Line 980:
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());</langsyntaxhighlight>
{{out}}
<pre>
Line 990:
{{works with|Rhino}}
{{works with|SpiderMonkey}}
<langsyntaxhighlight JavaScriptlang="javascript">var s1 = "Hello";
s1 += ", World!";
print(s1);
Line 997:
// 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:
 
=={{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:
s2.concat(', World!') ==> Goodbye, World!
=!EXPECTEND!=
*/</langsyntaxhighlight>
 
{{out}}
Line 1,034:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">s = "Hello"
s *= ", world!"</langsyntaxhighlight>
{{out}}
<pre>"Hello, world!"</pre>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="kotlin">fun main(args: Array<String>) {
var s = "a"
s += "b"
Line 1,050:
val c = "c"
println("$a$b$c")
}</langsyntaxhighlight>
{{out}}
<pre>abc
Line 1,058:
=={{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:
{christian_name} {name}
-> Albert de Jeumont-Schneidre
</syntaxhighlight>
</lang>
 
=={{header|langur}}==
<langsyntaxhighlight lang="langur">var .s = "no more "
.s ~= "foo bars"
writeln .s</langsyntaxhighlight>
 
{{out}}
Line 1,077:
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">local(x = 'Hello')
#x->append(', World!')
#x</langsyntaxhighlight>
{{out}}
<pre>Hello, World!</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:
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>
Line 1,122:
Documents in M2000 are objects with paragraphs.
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
a$="ok"
a$+="(one)"
Line 1,131:
b$="(one)"
Print b$
</syntaxhighlight>
</lang>
{{out}}
<pre>ok(one)
Line 1,138:
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">a := "Hello";
b := cat(a, " World");
c := `||`(a, " World");</langsyntaxhighlight>
{{out}}
<pre>
Line 1,149:
 
=={{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:
=={{header|min}}==
{{works with|min|0.19.6}}
<langsyntaxhighlight lang="min">(quote cons "" join) :str-append
 
"foo" "bar" str-append puts!</langsyntaxhighlight>
{{out}}
<pre>
Line 1,167:
 
=={{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:
The plus operator +, concats strings.
<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
<doc><p>String append in Neko</pre></doc>
**/
Line 1,190:
var str = "Hello"
str += ", world"
$print(str, "\n")</langsyntaxhighlight>
{{out}}
<pre>prompt$ nekoc string-append.neko
Line 1,197:
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">s_ = 'Hello'
s_ = s_', world!'
say s_</langsyntaxhighlight>
{{out}}
<pre>
Line 1,206:
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">(setq str "foo")
 
(push "bar" str -1)
Line 1,213:
 
(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:
 
=={{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:
}
}
</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:
=={{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:
{{works with|Free Pascal|2.6.2}}
 
<langsyntaxhighlight Pascallang="pascal">program StringAppend;
{$mode objfpc}{$H+}
 
Line 1,281:
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:
=={{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,305:
 
=={{header|Picat}}==
<langsyntaxhighlight Picatlang="picat">main =>
S = "a string",
S := S + " that is longer",
println(S).</langsyntaxhighlight>
 
{{out}}
Line 1,315:
 
=={{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,333:
 
=={{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,348:
Write the string to the console.
Wait for the escape key.
Shut down.</langsyntaxhighlight>
{{out}}
<pre>
Line 1,356:
=={{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,362:
\addtomacro\foo{ world!}
Appended: \foo
\bye</langsyntaxhighlight>
 
pdf or dvi output:
Line 1,370:
 
=={{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,386:
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,403:
 
=={{header|QB64}}==
<langsyntaxhighlight lang="qbasic">s$ = "String"
s$ = s$ + " append"
Print s$</langsyntaxhighlight>
{{out}}
<pre>String append</pre>
Line 1,413:
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,424:
 
=={{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,435:
(define mymacrostr "foo")
(set-append! mymacrostr " bar")
(displayln mystr)</langsyntaxhighlight>
 
{{out}}
Line 1,445:
=={{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,470:
 
===using concatenation===
<langsyntaxhighlight lang="rexx">s="He"
s=s || 'llo, World!' /*same as: s=s||'llo, World!' */
say s</langsyntaxhighlight>
'''output'''
<pre>
Line 1,479:
 
=={{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|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,508:
let hello = String::from("Hello world");
println!("{}", hello.add("!!!!"));
}</langsyntaxhighlight>
{{out}}
Hello world!!!!
Line 1,514:
=== 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,520:
println!("{}", hello);
}
</syntaxhighlight>
</lang>
{{out}}
Hello world!!!!
Line 1,526:
=={{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,533:
val f2 = () => " !" //Function assigned to variable
//> f2 : () => String = <function0>
println(s1 + f2()); //> HelloHello !</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 1,544:
str &:= "9!";
writeln(str);
end func;</langsyntaxhighlight>
 
{{out}}
Line 1,552:
 
=={{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,597:
(textout s1))
)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,604:
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">decl string str
set str "hello "
 
Line 1,611:
 
# 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|Vlang}}==
<langsyntaxhighlight lang="vlang">mut s:= 'foo'
s += 'bar'
println(s)
Line 1,643:
bar := 'bar'
foobar := '$foo$bar'
println(foobar)</langsyntaxhighlight>
 
{{out}}
Line 1,654:
 
=={{header|Wart}}==
<langsyntaxhighlight lang="python">s <- "12345678"
s <- (s + "9!")</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight lang="javascript">var s = "Hello, "
s = s + "world!"
System.print(s)</langsyntaxhighlight>
 
{{out}}
Line 1,668:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include xpllib;
char A, B, C(80);
[A:= "Hello, ";
Line 1,675:
StrCat(C, B);
Text(0, C);
]</langsyntaxhighlight>
 
{{out}}
Line 1,684:
=={{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,690:
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}}
10,327

edits