String append: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 18: | Line 18: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">V s = ‘12345678’ |
||
s ‘’= ‘9!’ |
s ‘’= ‘9!’ |
||
print(s)</ |
print(s)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 29: | Line 29: | ||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
||
<syntaxhighlight lang="aarch64 assembly"> |
|||
<lang AArch64 Assembly> |
|||
/* ARM assembly AARCH64 Raspberry PI 3B */ |
/* ARM assembly AARCH64 Raspberry PI 3B */ |
||
/* program appendstr64.s */ |
/* program appendstr64.s */ |
||
Line 116: | Line 116: | ||
/* for this file see task include a file in language AArch64 assembly */ |
/* for this file see task include a file in language AArch64 assembly */ |
||
.include "../includeARM64.inc" |
.include "../includeARM64.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Output}} |
{{Output}} |
||
<pre> |
<pre> |
||
Line 126: | Line 126: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
<syntaxhighlight lang="action!"> |
|||
<lang Action!> |
|||
CHAR ARRAY S1,S2 |
CHAR ARRAY S1,S2 |
||
Line 135: | Line 135: | ||
Print(S1) |
Print(S1) |
||
Return |
Return |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 143: | Line 143: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada"> |
||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; |
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; |
||
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO; |
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO; |
||
Line 153: | Line 153: | ||
Put_Line(Str); |
Put_Line(Str); |
||
end String_Append; |
end String_Append; |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 163: | 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|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).}} |
{{works with|ELLA ALGOL 68|Any (with appropriate job cards).}} |
||
'''File: String_append.a68'''< |
'''File: String_append.a68'''<syntaxhighlight lang="algol68">#!/usr/bin/a68g --script # |
||
# -*- coding: utf-8 -*- # |
# -*- coding: utf-8 -*- # |
||
STRING str := "12345678"; |
STRING str := "12345678"; |
||
str +:= "9!"; |
str +:= "9!"; |
||
print(str)</ |
print(str)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 176: | Line 176: | ||
=={{header|ARM Assembly}}== |
=={{header|ARM Assembly}}== |
||
{{works with|as|Raspberry Pi}} |
{{works with|as|Raspberry Pi}} |
||
<syntaxhighlight lang="arm assembly"> |
|||
<lang ARM Assembly> |
|||
/* ARM assembly Raspberry PI */ |
/* ARM assembly Raspberry PI */ |
||
/* program appendstr.s */ |
/* program appendstr.s */ |
||
Line 274: | Line 274: | ||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
<syntaxhighlight lang="applescript"> |
|||
<lang AppleScript> |
|||
set {a, b} to {"Apple", "Script"} |
set {a, b} to {"Apple", "Script"} |
||
set a to a & b |
set a to a & b |
||
return a as string |
return a as string |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 289: | Line 289: | ||
=={{header|APL}}== |
=={{header|APL}}== |
||
< |
<syntaxhighlight lang="apl"> s←'hello' |
||
s,'world' |
s,'world' |
||
helloworld</ |
helloworld</syntaxhighlight> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">print join ["Hello" "World"] |
||
a: new "Hello" |
a: new "Hello" |
||
Line 305: | Line 305: | ||
c: "Hello" |
c: "Hello" |
||
print append c "World"</ |
print append c "World"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 315: | Line 315: | ||
=={{header|Asymptote}}== |
=={{header|Asymptote}}== |
||
< |
<syntaxhighlight lang="asymptote">string s = "Hello"; |
||
s = s + " Wo"; |
s = s + " Wo"; |
||
s += "rld!"; |
s += "rld!"; |
||
write(s);</ |
write(s);</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">s := "Hello, " |
||
s .= "world." |
s .= "world." |
||
MsgBox % s</ |
MsgBox % s</syntaxhighlight> |
||
{{out}}<pre>Hello, world.</pre> |
{{out}}<pre>Hello, world.</pre> |
||
Line 329: | Line 329: | ||
Avail's normal strings are immutable, however string ''variables'' can leverage tuple's appending-assignment method, <code>_↑++=_</code>. |
Avail's normal strings are immutable, however string ''variables'' can leverage tuple's appending-assignment method, <code>_↑++=_</code>. |
||
< |
<syntaxhighlight lang="avail">str : string := "99 bottles of "; |
||
str ++= "beer"; |
str ++= "beer"; |
||
Print: str;</ |
Print: str;</syntaxhighlight> |
||
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: |
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: |
||
< |
<syntaxhighlight lang="avail">Public method "_↑++=_" is |
||
[ |
[ |
||
var : read tuple/write ⊥, |
var : read tuple/write ⊥, |
||
Line 341: | Line 341: | ||
| |
| |
||
var ?= eject var ++ t; |
var ?= eject var ++ t; |
||
] : ⊤;</ |
] : ⊤;</syntaxhighlight> |
||
(<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.) |
(<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}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f STRING_APPEND.AWK |
# syntax: GAWK -f STRING_APPEND.AWK |
||
BEGIN { |
BEGIN { |
||
Line 353: | Line 353: | ||
exit(0) |
exit(0) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 360: | Line 360: | ||
=={{header|Axe}}== |
=={{header|Axe}}== |
||
< |
<syntaxhighlight lang="axe">Lbl STRCAT |
||
Copy(r₂,r₁+length(r₁),length(r₂)+1) |
Copy(r₂,r₁+length(r₁),length(r₂)+1) |
||
r₁ |
r₁ |
||
Return</ |
Return</syntaxhighlight> |
||
Line 369: | Line 369: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
==={{header|Applesoft BASIC}}=== |
==={{header|Applesoft BASIC}}=== |
||
< |
<syntaxhighlight lang="basic">S$ = "Hello" |
||
S$ = S$ + " World!" |
S$ = S$ + " World!" |
||
PRINT S$</ |
PRINT S$</syntaxhighlight> |
||
==={{header|BaCon}}=== |
==={{header|BaCon}}=== |
||
< |
<syntaxhighlight lang="freebasic"> |
||
A$ = "Hello" |
A$ = "Hello" |
||
A$ = A$ & " World!" |
A$ = A$ & " World!" |
||
PRINT A$ |
PRINT A$ |
||
</ |
</syntaxhighlight> |
||
==={{header|BBC BASIC}}=== |
==={{header|BBC BASIC}}=== |
||
< |
<syntaxhighlight lang="bbc basic"> S$="Hello" |
||
S$+=" World!" |
S$+=" World!" |
||
PRINT S$ |
PRINT S$ |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hello World!</pre> |
<pre>Hello World!</pre> |
||
==={{header|Commodore BASIC}}=== |
==={{header|Commodore BASIC}}=== |
||
< |
<syntaxhighlight lang="gwbasic">10 S$ = "HELLO" |
||
20 S$ = S$ + " WORLD!" |
20 S$ = S$ + " WORLD!" |
||
30 PRINT S$ |
30 PRINT S$ |
||
40 END</ |
40 END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>HELLO WORLD!</pre> |
<pre>HELLO WORLD!</pre> |
||
==={{header|IS-BASIC}}=== |
==={{header|IS-BASIC}}=== |
||
< |
<syntaxhighlight lang="is-basic">100 LET S$="Hello" |
||
110 LET S$=S$&" World!" |
110 LET S$=S$&" World!" |
||
120 PRINT S$</ |
120 PRINT S$</syntaxhighlight> |
||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
< |
<syntaxhighlight lang="freebasic">a$ = "He" |
||
a$ = a$ & "llo" |
a$ = a$ & "llo" |
||
a$ = a$ + " Wo" |
a$ = a$ + " Wo" |
||
a$ += "rld" |
a$ += "rld" |
||
a$ &= "!" |
a$ &= "!" |
||
print a$</ |
print a$</syntaxhighlight> |
||
==={{header|Liberty BASIC}}=== |
==={{header|Liberty BASIC}}=== |
||
< |
<syntaxhighlight lang="lb">a$ = "Hello" |
||
a$ = a$ + " World" |
a$ = a$ + " World" |
||
a$ = a$ ; "!" |
a$ = a$ ; "!" |
||
print a$</ |
print a$</syntaxhighlight> |
||
==={{header|QBasic}}=== |
==={{header|QBasic}}=== |
||
Line 421: | Line 421: | ||
{{works with|Run BASIC}} |
{{works with|Run BASIC}} |
||
{{works with|Yabasic}} |
{{works with|Yabasic}} |
||
< |
<syntaxhighlight lang="qbasic">a$ = "Hello" |
||
a$ = a$ + " World!" |
a$ = a$ + " World!" |
||
PRINT a$</ |
PRINT a$</syntaxhighlight> |
||
==={{header|Run BASIC}}=== |
==={{header|Run BASIC}}=== |
||
Line 430: | Line 430: | ||
{{works with|QBasic}} |
{{works with|QBasic}} |
||
{{works with|Yabasic}} |
{{works with|Yabasic}} |
||
< |
<syntaxhighlight lang="runbasic">a$ = "Hello" |
||
a$ = a$ + " World!" |
a$ = a$ + " World!" |
||
print a$</ |
print a$</syntaxhighlight> |
||
==={{header|True BASIC}}=== |
==={{header|True BASIC}}=== |
||
< |
<syntaxhighlight lang="qbasic">LET a$ = "Hello" |
||
LET a$ = a$ & " World!" |
LET a$ = a$ & " World!" |
||
PRINT a$ |
PRINT a$ |
||
END</ |
END</syntaxhighlight> |
||
==={{header|Yabasic}}=== |
==={{header|Yabasic}}=== |
||
Line 445: | Line 445: | ||
{{works with|QBasic}} |
{{works with|QBasic}} |
||
{{works with|Run BASIC}} |
{{works with|Run BASIC}} |
||
< |
<syntaxhighlight lang="yabasic">a$ = "Hello" |
||
a$ = a$ + " World!" |
a$ = a$ + " World!" |
||
print a$</ |
print a$</syntaxhighlight> |
||
=={{header|Bracmat}}== |
=={{header|Bracmat}}== |
||
< |
<syntaxhighlight lang="bracmat">str="Hello"; |
||
str$(!str " World!"):?str; |
str$(!str " World!"):?str; |
||
out$!str;</ |
out$!str;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hello World!</pre> |
<pre>Hello World!</pre> |
||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include<stdio.h> |
||
#include<string.h> |
#include<string.h> |
||
Line 482: | Line 482: | ||
} |
} |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Good Morning to all !!!</pre> |
<pre>Good Morning to all !!!</pre> |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang="csharp">class Program |
||
{ |
{ |
||
static void Main(string[] args) |
static void Main(string[] args) |
||
Line 495: | Line 495: | ||
System.Console.WriteLine(x); |
System.Console.WriteLine(x); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#include <string> |
#include <string> |
||
Line 506: | Line 506: | ||
std::cout << greeting << std::endl ; |
std::cout << greeting << std::endl ; |
||
return 0 ; |
return 0 ; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hello , world!</pre> |
<pre>Hello , world!</pre> |
||
Line 512: | Line 512: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
Using global vars. |
Using global vars. |
||
< |
<syntaxhighlight lang="clojure">user=> (def s "app") |
||
#'user/s |
#'user/s |
||
user=> s |
user=> s |
||
Line 519: | Line 519: | ||
#'user/s |
#'user/s |
||
user=> s |
user=> s |
||
"append"</ |
"append"</syntaxhighlight> |
||
Using local bindings. |
Using local bindings. |
||
< |
<syntaxhighlight lang="clojure"> |
||
user=> (let [s "ap", s (str s "pend")] s) |
user=> (let [s "ap", s (str s "pend")] s) |
||
"append"</ |
"append"</syntaxhighlight> |
||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
Line 532: | Line 532: | ||
{{works with|GnuCOBOL}} |
{{works with|GnuCOBOL}} |
||
< |
<syntaxhighlight lang="cobol"> identification division. |
||
program-id. string-append. |
program-id. string-append. |
||
Line 555: | Line 555: | ||
goback. |
goback. |
||
end program string-append. |
end program string-append. |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>$ cobc -xj string-append.cob |
<pre>$ cobc -xj string-append.cob |
||
Line 562: | Line 562: | ||
=={{header|CoffeeScript}}== |
=={{header|CoffeeScript}}== |
||
{{works with|Node.js}} |
{{works with|Node.js}} |
||
< |
<syntaxhighlight lang="coffeescript">a = "Hello, " |
||
b = "World!" |
b = "World!" |
||
c = a + b |
c = a + b |
||
console.log c</ |
console.log c</syntaxhighlight> |
||
Or with concat: |
Or with concat: |
||
< |
<syntaxhighlight lang="coffeescript">console.log "Hello, ".concat "World!"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hello, World!</pre> |
<pre>Hello, World!</pre> |
||
Line 574: | Line 574: | ||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Similar to the [[String append#Racket| Racket]] solution, a macro is necessary to append in-place: |
Similar to the [[String append#Racket| Racket]] solution, a macro is necessary to append in-place: |
||
< |
<syntaxhighlight lang="lisp">(defmacro concatenatef (s &rest strs) |
||
"Append additional strings to the first string in-place." |
"Append additional strings to the first string in-place." |
||
`(setf ,s (concatenate 'string ,s ,@strs))) |
`(setf ,s (concatenate 'string ,s ,@strs))) |
||
Line 581: | Line 581: | ||
(format T "~a~%" *str*) |
(format T "~a~%" *str*) |
||
(concatenatef *str* "baz" "abc" "def") |
(concatenatef *str* "baz" "abc" "def") |
||
(format T "~a~%" *str*)</ |
(format T "~a~%" *str*)</syntaxhighlight> |
||
Output: |
Output: |
||
Line 588: | Line 588: | ||
=={{header|D}}== |
=={{header|D}}== |
||
< |
<syntaxhighlight lang="d">import std.stdio; |
||
void main() { |
void main() { |
||
Line 594: | Line 594: | ||
s ~= " world!"; |
s ~= " world!"; |
||
writeln(s); |
writeln(s); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hello world!</pre> |
<pre>Hello world!</pre> |
||
Line 600: | Line 600: | ||
=={{header|DBL}}== |
=={{header|DBL}}== |
||
< |
<syntaxhighlight lang="dbl">;Concatenate "Hello world!" |
||
STR='Hello' |
STR='Hello' |
||
STR(%TRIM(STR)+2:5)='world' |
STR(%TRIM(STR)+2:5)='world' |
||
STR(%TRIM(STR)+1:1)='!'</ |
STR(%TRIM(STR)+1:1)='!'</syntaxhighlight> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
{{libheader| System.SysUtils}} |
{{libheader| System.SysUtils}} |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program String_append; |
program String_append; |
||
Line 645: | Line 645: | ||
writeln(h); |
writeln(h); |
||
readln; |
readln; |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hello World |
<pre>Hello World |
||
Line 653: | Line 653: | ||
=={{header|Dyalect}}== |
=={{header|Dyalect}}== |
||
< |
<syntaxhighlight lang="dyalect">var str = "foo" |
||
str += str |
str += str |
||
print(str)</ |
print(str)</syntaxhighlight> |
||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
<lang>a$ = "hello" |
<syntaxhighlight lang="text">a$ = "hello" |
||
a$ &= " world" |
a$ &= " world" |
||
print a$</ |
print a$</syntaxhighlight> |
||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |
||
< |
<syntaxhighlight lang="lisp"> |
||
;; Solution from Common Lisp and Racket |
;; Solution from Common Lisp and Racket |
||
(define-syntax-rule (set-append! str tail) |
(define-syntax-rule (set-append! str tail) |
||
Line 673: | Line 673: | ||
name |
name |
||
→ "Albert de Jeumont-Schneidre" |
→ "Albert de Jeumont-Schneidre" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA 4.x : |
ELENA 4.x : |
||
< |
<syntaxhighlight lang="elena">import extensions; |
||
import extensions'text; |
import extensions'text; |
||
Line 686: | Line 686: | ||
console.printLine:s.readChar() |
console.printLine:s.readChar() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
< |
<syntaxhighlight lang="elixir">iex(60)> s = "Hello" |
||
"Hello" |
"Hello" |
||
iex(61)> s <> " World!" |
iex(61)> s <> " World!" |
||
"Hello World!"</ |
"Hello World!"</syntaxhighlight> |
||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
Line 698: | 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: |
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")) |
(setq str (concat str "bar")) |
||
str ;=> "foobar"</ |
str ;=> "foobar"</syntaxhighlight> |
||
This can be hidden by using a macro such as <code>cl-callf</code> which expands into the above code: |
This can be hidden by using a macro such as <code>cl-callf</code> which expands into the above code: |
||
{{libheader|cl-lib}} |
{{libheader|cl-lib}} |
||
< |
<syntaxhighlight lang="lisp">(require 'cl-lib) |
||
(defvar str "foo") |
(defvar str "foo") |
||
(cl-callf concat str "bar") |
(cl-callf concat str "bar") |
||
str ;=> "foobar"</ |
str ;=> "foobar"</syntaxhighlight> |
||
Buffers can be thought of as expandable strings: |
Buffers can be thought of as expandable strings: |
||
< |
<syntaxhighlight lang="lisp">(let ((buf (get-buffer-create "*foo*"))) |
||
(with-current-buffer buf |
(with-current-buffer buf |
||
(insert "foo")) |
(insert "foo")) |
||
Line 720: | Line 720: | ||
(insert "bar") |
(insert "bar") |
||
(buffer-string))) |
(buffer-string))) |
||
;; => "foobar"</ |
;; => "foobar"</syntaxhighlight> |
||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
Line 732: | Line 732: | ||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |
||
< |
<syntaxhighlight lang="euphoria"> |
||
sequence string = "String" |
sequence string = "String" |
||
Line 740: | Line 740: | ||
printf(1,"%s",{string}) |
printf(1,"%s",{string}) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 749: | Line 749: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
Strings are immutable in .NET. To append (to the same variable) the variable has to be declared mutable. |
Strings are immutable in .NET. To append (to the same variable) the variable has to be declared mutable. |
||
< |
<syntaxhighlight lang="fsharp">let mutable x = "foo" |
||
x <- x + "bar" |
x <- x + "bar" |
||
printfn "%s" x</ |
printfn "%s" x</syntaxhighlight> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">"Hello, " "world!" append</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 761: | Line 761: | ||
=={{header|Falcon}}== |
=={{header|Falcon}}== |
||
< |
<syntaxhighlight lang="falcon"> |
||
/* Added by Aykayayciti Earl Lamont Montgomery |
/* Added by Aykayayciti Earl Lamont Montgomery |
||
April 10th, 2018 */ |
April 10th, 2018 */ |
||
Line 768: | Line 768: | ||
> s1 + " World" |
> s1 + " World" |
||
printl(s2 + " bar") |
printl(s2 + " bar") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 777: | Line 777: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
< |
<syntaxhighlight lang="forth">\ Strings in Forth are simply named memory locations |
||
create astring 256 allot \ create a "string" |
create astring 256 allot \ create a "string" |
||
Line 783: | Line 783: | ||
s" Hello " astring PLACE \ initialize the string |
s" Hello " astring PLACE \ initialize the string |
||
s" World!" astring +PLACE \ append with "+place"</ |
s" World!" astring +PLACE \ append with "+place"</syntaxhighlight> |
||
Test at the console |
Test at the console |
||
<lang> ok |
<syntaxhighlight lang="text"> ok |
||
s" Hello " astring place ok |
s" Hello " astring place ok |
||
s" World!" astring +place ok |
s" World!" astring +place ok |
||
astring count type Hello World! ok |
astring count type Hello World! ok |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Line 797: | Line 797: | ||
'''Using deferred length character strings:''' |
'''Using deferred length character strings:''' |
||
<syntaxhighlight lang="fortran"> |
|||
<lang Fortran> |
|||
program main |
program main |
||
Line 808: | Line 808: | ||
end program main |
end program main |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 816: | Line 816: | ||
'''Using pre-allocated character strings:''' |
'''Using pre-allocated character strings:''' |
||
<syntaxhighlight lang="fortran"> |
|||
<lang Fortran> |
|||
program str_append |
program str_append |
||
implicit none |
implicit none |
||
Line 827: | Line 827: | ||
end program str_append |
end program str_append |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 833: | Line 833: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64 |
||
Var s = "String" |
Var s = "String" |
||
s += " append" |
s += " append" |
||
Print s |
Print s |
||
Sleep</ |
Sleep</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 847: | Line 847: | ||
=={{header|Gambas}}== |
=={{header|Gambas}}== |
||
'''[https://gambas-playground.proko.eu/?gist=0b17e205d56985c8cd1ff108c6fc9ca4 Click this link to run this code]''' |
'''[https://gambas-playground.proko.eu/?gist=0b17e205d56985c8cd1ff108c6fc9ca4 Click this link to run this code]''' |
||
< |
<syntaxhighlight lang="gambas">Public Sub Main() |
||
Dim sString As String = "Hello " |
Dim sString As String = "Hello " |
||
Line 853: | Line 853: | ||
Print sString |
Print sString |
||
End</ |
End</syntaxhighlight> |
||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 860: | Line 860: | ||
=={{header|Genie}}== |
=={{header|Genie}}== |
||
< |
<syntaxhighlight lang="genie">[indent=4] |
||
/* String append, in Genie */ |
/* String append, in Genie */ |
||
init |
init |
||
Line 866: | Line 866: | ||
str += ", world" |
str += ", world" |
||
print str</ |
print str</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>prompt$ valac stringAppend.gs |
<pre>prompt$ valac stringAppend.gs |
||
Line 873: | Line 873: | ||
=={{header|GlovePIE}}== |
=={{header|GlovePIE}}== |
||
< |
<syntaxhighlight lang="glovepie">var.string="This is " |
||
var.string+="Sparta!" |
var.string+="Sparta!" |
||
debug=var.string</ |
debug=var.string</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">s := "foo" |
||
s += "bar"</ |
s += "bar"</syntaxhighlight> |
||
=== String Builder === |
=== 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. |
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 |
package main |
||
Line 897: | Line 897: | ||
fmt.Print(s.String()) |
fmt.Print(s.String()) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
foobar |
foobar |
||
=={{header|Gosu}}== |
=={{header|Gosu}}== |
||
< |
<syntaxhighlight lang="gosu">// Example 1 |
||
var s = "a" |
var s = "a" |
||
s += "b" |
s += "b" |
||
Line 915: | Line 915: | ||
var b = "b" |
var b = "b" |
||
var c = "c" |
var c = "c" |
||
print("${a}${b}${c}")</ |
print("${a}${b}${c}")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 924: | Line 924: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
<syntaxhighlight lang="groovy"> |
|||
<lang Groovy> |
|||
class Append{ |
class Append{ |
||
static void main(String[] args){ |
static void main(String[] args){ |
||
Line 933: | Line 933: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 941: | Line 941: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell"> |
||
main = putStrLn ("Hello" ++ "World") |
main = putStrLn ("Hello" ++ "World") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
In both languages you can: |
In both languages you can: |
||
< |
<syntaxhighlight lang="unicon"> |
||
procedure main() |
procedure main() |
||
s := "foo" |
s := "foo" |
||
Line 954: | Line 954: | ||
write(s) |
write(s) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
Outputs: |
Outputs: |
||
Line 965: | Line 965: | ||
=={{header|J}}== |
=={{header|J}}== |
||
< |
<syntaxhighlight lang="j"> s=: 'new' |
||
s |
s |
||
new |
new |
||
s=: s,' value' NB. append is in-place |
s=: s,' value' NB. append is in-place |
||
s |
s |
||
new value</ |
new value</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">String sa = "Hello"; |
||
sa += ", World!"; |
sa += ", World!"; |
||
System.out.println(sa); |
System.out.println(sa); |
||
Line 980: | Line 980: | ||
ba.append("Hello"); |
ba.append("Hello"); |
||
ba.append(", World!"); |
ba.append(", World!"); |
||
System.out.println(ba.toString());</ |
System.out.println(ba.toString());</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 990: | Line 990: | ||
{{works with|Rhino}} |
{{works with|Rhino}} |
||
{{works with|SpiderMonkey}} |
{{works with|SpiderMonkey}} |
||
< |
<syntaxhighlight lang="javascript">var s1 = "Hello"; |
||
s1 += ", World!"; |
s1 += ", World!"; |
||
print(s1); |
print(s1); |
||
Line 997: | Line 997: | ||
// concat() returns the strings together, but doesn't edit existing string |
// concat() returns the strings together, but doesn't edit existing string |
||
// concat can also have multiple parameters |
// concat can also have multiple parameters |
||
print(s2.concat(", World!"));</ |
print(s2.concat(", World!"));</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,005: | Line 1,005: | ||
=={{header|jq}}== |
=={{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:< |
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:<syntaxhighlight lang="jq">"Hello" | . += ", world!" |
||
["Hello"] | .[0] += ", world!" | .[0] |
["Hello"] | .[0] += ", world!" | .[0] |
||
{ "greeting": "Hello"} | .greeting += ", world!" | .greeting</ |
{ "greeting": "Hello"} | .greeting += ", world!" | .greeting</syntaxhighlight> |
||
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:< |
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:<syntaxhighlight lang="jq">"Hello" as $a | $a | . += ", world!" as $a | $a</syntaxhighlight> |
||
=={{header|Jsish}}== |
=={{header|Jsish}}== |
||
From Javascript entry. |
From Javascript entry. |
||
< |
<syntaxhighlight lang="javascript">/* String append, in Jsish */ |
||
var str = 'Hello'; |
var str = 'Hello'; |
||
;str += ', world'; |
;str += ', world'; |
||
Line 1,026: | Line 1,026: | ||
s2.concat(', World!') ==> Goodbye, World! |
s2.concat(', World!') ==> Goodbye, World! |
||
=!EXPECTEND!= |
=!EXPECTEND!= |
||
*/</ |
*/</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,034: | Line 1,034: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">s = "Hello" |
||
s *= ", world!"</ |
s *= ", world!"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>"Hello, world!"</pre> |
<pre>"Hello, world!"</pre> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="kotlin">fun main(args: Array<String>) { |
||
var s = "a" |
var s = "a" |
||
s += "b" |
s += "b" |
||
Line 1,050: | Line 1,050: | ||
val c = "c" |
val c = "c" |
||
println("$a$b$c") |
println("$a$b$c") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>abc |
<pre>abc |
||
Line 1,058: | Line 1,058: | ||
=={{header|Lambdatalk}}== |
=={{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. |
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} |
{def christian_name Albert} |
||
-> christian_name |
-> christian_name |
||
Line 1,066: | Line 1,066: | ||
{christian_name} {name} |
{christian_name} {name} |
||
-> Albert de Jeumont-Schneidre |
-> Albert de Jeumont-Schneidre |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|langur}}== |
=={{header|langur}}== |
||
< |
<syntaxhighlight lang="langur">var .s = "no more " |
||
.s ~= "foo bars" |
.s ~= "foo bars" |
||
writeln .s</ |
writeln .s</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,077: | Line 1,077: | ||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
< |
<syntaxhighlight lang="lasso">local(x = 'Hello') |
||
#x->append(', World!') |
#x->append(', World!') |
||
#x</ |
#x</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hello, World!</pre> |
<pre>Hello, World!</pre> |
||
=={{header|Lingo}}== |
=={{header|Lingo}}== |
||
< |
<syntaxhighlight lang="lingo">str = "Hello" |
||
put " world!" after str |
put " world!" after str |
||
put str |
put str |
||
-- "Hello world!"</ |
-- "Hello world!"</syntaxhighlight> |
||
=={{header|LiveCode}}== |
=={{header|LiveCode}}== |
||
Livecode has an "after" keyword for this |
Livecode has an "after" keyword for this |
||
< |
<syntaxhighlight lang="livecode">local str="live" |
||
put "code" after str</ |
put "code" after str</syntaxhighlight> |
||
Output is "livecode" |
Output is "livecode" |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Not possible as strings are immutable. We can demonstrate their immutability using 'self': |
Not possible as strings are immutable. We can demonstrate their immutability using 'self': |
||
< |
<syntaxhighlight lang="lua">function string:show () |
||
print(self) |
print(self) |
||
end |
end |
||
Line 1,108: | Line 1,108: | ||
x:show() |
x:show() |
||
x:append("there!") |
x:append("there!") |
||
x:show()</ |
x:show()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hi |
<pre>Hi |
||
Hi </pre> |
Hi </pre> |
||
You can of course concatentate them and store the result in the original variable name but that requires a double reference: |
You can of course concatentate them and store the result in the original variable name but that requires a double reference: |
||
< |
<syntaxhighlight lang="lua">x = "Hi " |
||
x = x .. "there!" |
x = x .. "there!" |
||
print(x)</ |
print(x)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hi there!</pre> |
<pre>Hi there!</pre> |
||
Line 1,122: | Line 1,122: | ||
Documents in M2000 are objects with paragraphs. |
Documents in M2000 are objects with paragraphs. |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
a$="ok" |
a$="ok" |
||
a$+="(one)" |
a$+="(one)" |
||
Line 1,131: | Line 1,131: | ||
b$="(one)" |
b$="(one)" |
||
Print b$ |
Print b$ |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>ok(one) |
<pre>ok(one) |
||
Line 1,138: | Line 1,138: | ||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
< |
<syntaxhighlight lang="maple">a := "Hello"; |
||
b := cat(a, " World"); |
b := cat(a, " World"); |
||
c := `||`(a, " World");</ |
c := `||`(a, " World");</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,149: | Line 1,149: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">(* mutable strings are not supported *) |
||
s1 = "testing"; |
s1 = "testing"; |
||
s1 = s1 <> " 123"; |
s1 = s1 <> " 123"; |
||
s1</ |
s1</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>"testing 123"</pre> |
<pre>"testing 123"</pre> |
||
Line 1,158: | Line 1,158: | ||
=={{header|min}}== |
=={{header|min}}== |
||
{{works with|min|0.19.6}} |
{{works with|min|0.19.6}} |
||
< |
<syntaxhighlight lang="min">(quote cons "" join) :str-append |
||
"foo" "bar" str-append puts!</ |
"foo" "bar" str-append puts!</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,167: | Line 1,167: | ||
=={{header|MontiLang}}== |
=={{header|MontiLang}}== |
||
< |
<syntaxhighlight lang="montilang">|Hello | |world!| swap + print</syntaxhighlight> |
||
< |
<syntaxhighlight lang="montilang">|Hello | var hello . |
||
|world!| var world . |
|world!| var world . |
||
world hello + print</ |
world hello + print</syntaxhighlight> |
||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
< |
<syntaxhighlight lang="nanoquery">s1 = "this is" |
||
s1 += " a test" |
s1 += " a test" |
||
println s1</ |
println s1</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,184: | Line 1,184: | ||
The plus operator +, concats strings. |
The plus operator +, concats strings. |
||
<syntaxhighlight lang="actionscript">/** |
|||
<lang ActionScript>/** |
|||
<doc><p>String append in Neko</pre></doc> |
<doc><p>String append in Neko</pre></doc> |
||
**/ |
**/ |
||
Line 1,190: | Line 1,190: | ||
var str = "Hello" |
var str = "Hello" |
||
str += ", world" |
str += ", world" |
||
$print(str, "\n")</ |
$print(str, "\n")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>prompt$ nekoc string-append.neko |
<pre>prompt$ nekoc string-append.neko |
||
Line 1,197: | Line 1,197: | ||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |
||
< |
<syntaxhighlight lang="netrexx">s_ = 'Hello' |
||
s_ = s_', world!' |
s_ = s_', world!' |
||
say s_</ |
say s_</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,206: | Line 1,206: | ||
=={{header|NewLISP}}== |
=={{header|NewLISP}}== |
||
< |
<syntaxhighlight lang="newlisp">(setq str "foo") |
||
(push "bar" str -1) |
(push "bar" str -1) |
||
Line 1,213: | Line 1,213: | ||
(println str) |
(println str) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">var str = "123456" |
||
str.add("78") # Using procedure "add". |
str.add("78") # Using procedure "add". |
||
str &= "9!" # Using operator "&=". |
str &= "9!" # Using operator "&=". |
||
echo str |
echo str |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,226: | Line 1,226: | ||
=={{header|NS-HUBASIC}}== |
=={{header|NS-HUBASIC}}== |
||
< |
<syntaxhighlight lang="ns-hubasic">10 S$ = "HELLO" |
||
20 S$ = S$ + " WORLD!" |
20 S$ = S$ + " WORLD!" |
||
30 PRINT S$</ |
30 PRINT S$</syntaxhighlight> |
||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
< |
<syntaxhighlight lang="objeck"> |
||
class Append { |
class Append { |
||
function : Main(args : String[]) ~ Nil { |
function : Main(args : String[]) ~ Nil { |
||
Line 1,239: | Line 1,239: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang="ocaml">let () = |
||
let s = Buffer.create 17 in |
let s = Buffer.create 17 in |
||
Buffer.add_string s "Bonjour"; |
Buffer.add_string s "Bonjour"; |
||
Buffer.add_string s " tout le monde!"; |
Buffer.add_string s " tout le monde!"; |
||
print_endline (Buffer.contents s)</ |
print_endline (Buffer.contents s)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Bonjour tout le monde!</pre> |
<pre>Bonjour tout le monde!</pre> |
||
Line 1,252: | Line 1,252: | ||
=={{header|Oforth}}== |
=={{header|Oforth}}== |
||
< |
<syntaxhighlight lang="oforth">StringBuffer new "Hello, " << "World!" << println</syntaxhighlight> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Not supported in GP. |
Not supported in GP. |
||
< |
<syntaxhighlight lang="parigp">s = "Hello"; |
||
s = Str(s, ", world!")</ |
s = Str(s, ", world!")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>%1 = "Hello, world!"</pre> |
<pre>%1 = "Hello, world!"</pre> |
||
Line 1,265: | Line 1,265: | ||
{{works with|Free Pascal|2.6.2}} |
{{works with|Free Pascal|2.6.2}} |
||
< |
<syntaxhighlight lang="pascal">program StringAppend; |
||
{$mode objfpc}{$H+} |
{$mode objfpc}{$H+} |
||
Line 1,281: | Line 1,281: | ||
WriteLn(S); |
WriteLn(S); |
||
ReadLn; |
ReadLn; |
||
end.</ |
end.</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>Hello World !</pre> |
<pre>Hello World !</pre> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">my $str = 'Foo'; |
||
$str .= 'bar'; |
$str .= 'bar'; |
||
print $str;</ |
print $str;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Foobar</pre> |
<pre>Foobar</pre> |
||
Line 1,294: | Line 1,294: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{libheader|Phix/basics}} |
{{libheader|Phix/basics}} |
||
<!--< |
<!--<syntaxhighlight lang="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: #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> |
<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> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,305: | Line 1,305: | ||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
< |
<syntaxhighlight lang="picat">main => |
||
S = "a string", |
S = "a string", |
||
S := S + " that is longer", |
S := S + " that is longer", |
||
println(S).</ |
println(S).</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,315: | Line 1,315: | ||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(setq Str1 "12345678") |
||
(setq Str1 (pack Str1 "9!")) |
(setq Str1 (pack Str1 "9!")) |
||
(println Str1)</ |
(println Str1)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>"123456789!"</pre> |
<pre>"123456789!"</pre> |
||
=={{header|Pike}}== |
=={{header|Pike}}== |
||
<syntaxhighlight lang="pike"> |
|||
<lang Pike> |
|||
string msg = "hello"; |
string msg = "hello"; |
||
msg += " world"; |
msg += " world"; |
||
write(msg +"\n"); |
write(msg +"\n"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre> |
<pre> |
||
Line 1,333: | Line 1,333: | ||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
< |
<syntaxhighlight lang="pl/i">Cat: procedure options (main); |
||
declare s character (100) varying; |
declare s character (100) varying; |
||
s = 'dust '; |
s = 'dust '; |
||
s ||= 'bowl'; |
s ||= 'bowl'; |
||
put (s); |
put (s); |
||
end Cat;</ |
end Cat;</syntaxhighlight> |
||
<pre>dust bowl</pre> |
<pre>dust bowl</pre> |
||
=={{header|Plain English}}== |
=={{header|Plain English}}== |
||
< |
<syntaxhighlight lang="plainenglish">To run: |
||
Start up. |
Start up. |
||
Put "abc" into a string. |
Put "abc" into a string. |
||
Line 1,348: | Line 1,348: | ||
Write the string to the console. |
Write the string to the console. |
||
Wait for the escape key. |
Wait for the escape key. |
||
Shut down.</ |
Shut down.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,356: | Line 1,356: | ||
=={{header|plainTeX}}== |
=={{header|plainTeX}}== |
||
Works with any TeX engine |
Works with any TeX engine |
||
< |
<syntaxhighlight lang="tex">\def\addtomacro#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}} |
||
\def\foo{Hello} |
\def\foo{Hello} |
||
Initial: \foo |
Initial: \foo |
||
Line 1,362: | Line 1,362: | ||
\addtomacro\foo{ world!} |
\addtomacro\foo{ world!} |
||
Appended: \foo |
Appended: \foo |
||
\bye</ |
\bye</syntaxhighlight> |
||
pdf or dvi output: |
pdf or dvi output: |
||
Line 1,370: | Line 1,370: | ||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
<syntaxhighlight lang="powershell"> |
|||
<lang PowerShell> |
|||
$str = "Hello, " |
$str = "Hello, " |
||
$str += "World!" |
$str += "World!" |
||
$str |
$str |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre>Hello, World!</pre> |
<pre>Hello, World!</pre> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">S$ = "Hello" |
||
S$ = S$ + " Wo" ;by referencing the string twice |
S$ = S$ + " Wo" ;by referencing the string twice |
||
S$ + "rld!" ;by referencing the string once |
S$ + "rld!" ;by referencing the string once |
||
Line 1,386: | Line 1,386: | ||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input() |
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input() |
||
CloseConsole() |
CloseConsole() |
||
EndIf</ |
EndIf</syntaxhighlight> |
||
Sample output: |
Sample output: |
||
<pre>Hello World!</pre> |
<pre>Hello World!</pre> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
'''File: String_append.py'''< |
'''File: String_append.py'''<syntaxhighlight lang="python">#!/usr/bin/env python |
||
# -*- coding: utf-8 -*- # |
# -*- coding: utf-8 -*- # |
||
str = "12345678"; |
str = "12345678"; |
||
str += "9!"; |
str += "9!"; |
||
print(str)</ |
print(str)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,403: | Line 1,403: | ||
=={{header|QB64}}== |
=={{header|QB64}}== |
||
< |
<syntaxhighlight lang="qbasic">s$ = "String" |
||
s$ = s$ + " append" |
s$ = s$ + " append" |
||
Print s$</ |
Print s$</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>String append</pre> |
<pre>String append</pre> |
||
Line 1,413: | 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>. |
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 |
$ "L'homme qui attend de voir un canard roti voler " temp put |
||
$ "dans sa bouche doit attendre tres, tres longtemps." temp append |
$ "dans sa bouche doit attendre tres, tres longtemps." temp append |
||
temp take echo$ </ |
temp take echo$ </syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,424: | Line 1,424: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket">;there is no built-in way to set! append in racket |
||
(define mystr "foo") |
(define mystr "foo") |
||
(set! mystr (string-append mystr " bar")) |
(set! mystr (string-append mystr " bar")) |
||
Line 1,435: | Line 1,435: | ||
(define mymacrostr "foo") |
(define mymacrostr "foo") |
||
(set-append! mymacrostr " bar") |
(set-append! mymacrostr " bar") |
||
(displayln mystr)</ |
(displayln mystr)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,445: | Line 1,445: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line>my $str = "foo"; |
||
$str ~= "bar"; |
$str ~= "bar"; |
||
say $str;</ |
say $str;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>foobar</pre> |
<pre>foobar</pre> |
||
=={{header|Relation}}== |
=={{header|Relation}}== |
||
<syntaxhighlight lang="relation"> |
|||
<lang Relation> |
|||
set a = "Hello" |
set a = "Hello" |
||
set b = " World" |
set b = " World" |
||
set c = a.b |
set c = a.b |
||
echo c |
echo c |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
===using abutment=== |
===using abutment=== |
||
< |
<syntaxhighlight lang="rexx">s='he' |
||
s=s'llo world!' |
s=s'llo world!' |
||
Say s</ |
Say s</syntaxhighlight> |
||
'''output''' |
'''output''' |
||
<pre> |
<pre> |
||
Line 1,470: | Line 1,470: | ||
===using concatenation=== |
===using concatenation=== |
||
< |
<syntaxhighlight lang="rexx">s="He" |
||
s=s || 'llo, World!' /*same as: s=s||'llo, World!' */ |
s=s || 'llo, World!' /*same as: s=s||'llo, World!' */ |
||
say s</ |
say s</syntaxhighlight> |
||
'''output''' |
'''output''' |
||
<pre> |
<pre> |
||
Line 1,479: | Line 1,479: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
aString1 = "Welcome to the " |
aString1 = "Welcome to the " |
||
aString2 = "Ring Programming Language" |
aString2 = "Ring Programming Language" |
||
aString3 = aString1 + aString2 |
aString3 = aString1 + aString2 |
||
see aString3 |
see aString3 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Robotic}}== |
=={{header|Robotic}}== |
||
< |
<syntaxhighlight lang="robotic"> |
||
set "$str1" to "Hello " |
set "$str1" to "Hello " |
||
inc "$str1" by "world!" |
inc "$str1" by "world!" |
||
* "&$str1&" |
* "&$str1&" |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">s = "Hello wo" |
||
s += "rld" # new string object |
s += "rld" # new string object |
||
s << "!" # mutates in place, same object |
s << "!" # mutates in place, same object |
||
puts s</ |
puts s</syntaxhighlight> |
||
{{out}}<pre>Hello world!</pre> |
{{out}}<pre>Hello world!</pre> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust"> |
||
use std::ops::Add; |
use std::ops::Add; |
||
Line 1,508: | Line 1,508: | ||
let hello = String::from("Hello world"); |
let hello = String::from("Hello world"); |
||
println!("{}", hello.add("!!!!")); |
println!("{}", hello.add("!!!!")); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Hello world!!!! |
Hello world!!!! |
||
Line 1,514: | Line 1,514: | ||
=== Real append === |
=== Real append === |
||
The first solution doesn't append to the string variable. This solution really appends to the existing variable. |
The first solution doesn't append to the string variable. This solution really appends to the existing variable. |
||
< |
<syntaxhighlight lang="rust"> |
||
fn main(){ |
fn main(){ |
||
let mut hello = String::from("Hello world"); |
let mut hello = String::from("Hello world"); |
||
Line 1,520: | Line 1,520: | ||
println!("{}", hello); |
println!("{}", hello); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Hello world!!!! |
Hello world!!!! |
||
Line 1,526: | Line 1,526: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
An evaluation in Scala worksheet. |
An evaluation in Scala worksheet. |
||
< |
<syntaxhighlight lang="scala"> var d = "Hello" // Mutables are discouraged //> d : String = Hello |
||
d += ", World!" // var contains a totally new re-instantiationed String |
d += ", World!" // var contains a totally new re-instantiationed String |
||
Line 1,533: | Line 1,533: | ||
val f2 = () => " !" //Function assigned to variable |
val f2 = () => " !" //Function assigned to variable |
||
//> f2 : () => String = <function0> |
//> f2 : () => String = <function0> |
||
println(s1 + f2()); //> HelloHello !</ |
println(s1 + f2()); //> HelloHello !</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
const proc: main is func |
const proc: main is func |
||
Line 1,544: | Line 1,544: | ||
str &:= "9!"; |
str &:= "9!"; |
||
writeln(str); |
writeln(str); |
||
end func;</ |
end func;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,552: | Line 1,552: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">var str = 'Foo'; |
||
str += 'bar'; |
str += 'bar'; |
||
say str;</ |
say str;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Foobar</pre> |
<pre>Foobar</pre> |
||
=={{header|SNOBOL4}}== |
=={{header|SNOBOL4}}== |
||
< |
<syntaxhighlight lang="snobol4"> s = "Hello" |
||
s = s ", World!" |
s = s ", World!" |
||
OUTPUT = s |
OUTPUT = s |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hello, World!</pre> |
<pre>Hello, World!</pre> |
||
=={{header|Stata}}== |
=={{header|Stata}}== |
||
< |
<syntaxhighlight lang="stata">sca s="Ars Longa" |
||
sca s=s+" Vita Brevis" |
sca s=s+" Vita Brevis" |
||
di s |
di s |
||
Ars Longa Vita Brevis</ |
Ars Longa Vita Brevis</syntaxhighlight> |
||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang="swift">var s = "foo" // "foo" |
||
s += "bar" // "foobar" |
s += "bar" // "foobar" |
||
print(s) // "foobar" |
print(s) // "foobar" |
||
s.appendContentsOf("baz") // "foobarbaz" |
s.appendContentsOf("baz") // "foobarbaz" |
||
print(s) // "foobarbaz"</ |
print(s) // "foobarbaz"</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{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: |
String concatenation is a fundamental feature of the Tcl language, and there is also an <code>append</code> that makes concatenation even simpler: |
||
< |
<syntaxhighlight lang="tcl">set s "he" |
||
set s "${s}llo wo"; # The braces distinguish varname from text to concatenate |
set s "${s}llo wo"; # The braces distinguish varname from text to concatenate |
||
append s "rld" |
append s "rld" |
||
puts $s</ |
puts $s</syntaxhighlight> |
||
{{out}}<pre>hello world</pre> |
{{out}}<pre>hello world</pre> |
||
=={{header|Transd}}== |
=={{header|Transd}}== |
||
< |
<syntaxhighlight lang="scheme">#lang transd |
||
MainModule: { |
MainModule: { |
||
Line 1,597: | Line 1,597: | ||
(textout s1)) |
(textout s1)) |
||
) |
) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,604: | Line 1,604: | ||
=={{header|Ursa}}== |
=={{header|Ursa}}== |
||
< |
<syntaxhighlight lang="ursa">decl string str |
||
set str "hello " |
set str "hello " |
||
Line 1,611: | Line 1,611: | ||
# outputs "hello world" |
# outputs "hello world" |
||
out str endl console</ |
out str endl console</syntaxhighlight> |
||
=={{header|Vala}}== |
=={{header|Vala}}== |
||
< |
<syntaxhighlight lang="vala">void main() { |
||
string x = "foo"; |
string x = "foo"; |
||
x += "bar\n"; |
x += "bar\n"; |
||
print(x); |
print(x); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|VBA}}== |
=={{header|VBA}}== |
||
< |
<syntaxhighlight lang="vb">Function StringAppend() |
||
Dim s As String |
Dim s As String |
||
s = "foo" |
s = "foo" |
||
s = s & "bar" |
s = s & "bar" |
||
Debug.Print s |
Debug.Print s |
||
End Function</ |
End Function</syntaxhighlight> |
||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
< |
<syntaxhighlight lang="vb">s = "Rosetta" |
||
s = s & " Code" |
s = s & " Code" |
||
WScript.StdOut.Write s</ |
WScript.StdOut.Write s</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Rosetta Code</pre> |
<pre>Rosetta Code</pre> |
||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
< |
<syntaxhighlight lang="vlang">mut s:= 'foo' |
||
s += 'bar' |
s += 'bar' |
||
println(s) |
println(s) |
||
Line 1,643: | Line 1,643: | ||
bar := 'bar' |
bar := 'bar' |
||
foobar := '$foo$bar' |
foobar := '$foo$bar' |
||
println(foobar)</ |
println(foobar)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,654: | Line 1,654: | ||
=={{header|Wart}}== |
=={{header|Wart}}== |
||
< |
<syntaxhighlight lang="python">s <- "12345678" |
||
s <- (s + "9!")</ |
s <- (s + "9!")</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
< |
<syntaxhighlight lang="javascript">var s = "Hello, " |
||
s = s + "world!" |
s = s + "world!" |
||
System.print(s)</ |
System.print(s)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,668: | Line 1,668: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">include xpllib; |
||
char A, B, C(80); |
char A, B, C(80); |
||
[A:= "Hello, "; |
[A:= "Hello, "; |
||
Line 1,675: | Line 1,675: | ||
StrCat(C, B); |
StrCat(C, B); |
||
Text(0, C); |
Text(0, C); |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,684: | Line 1,684: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
zkl strings are immutable, but byte blobs are mutable. |
zkl strings are immutable, but byte blobs are mutable. |
||
< |
<syntaxhighlight lang="zkl">var s="foo"; |
||
s.append("bar"); //-->new string "foobar", var s unchanged |
s.append("bar"); //-->new string "foobar", var s unchanged |
||
s+="bar"; //-->new string "foobar", var s modifed to new value |
s+="bar"; //-->new string "foobar", var s modifed to new value |
||
Line 1,690: | Line 1,690: | ||
s=Data(Void,"foo"); // byte blob/character blob/text editor buffer |
s=Data(Void,"foo"); // byte blob/character blob/text editor buffer |
||
s.append("bar"); // or s+="bar" |
s.append("bar"); // or s+="bar" |
||
s.text; //-->"foobar"</ |
s.text; //-->"foobar"</syntaxhighlight> |
||
{{omit from|bc|No string operations in bc}} |
{{omit from|bc|No string operations in bc}} |