String append: Difference between revisions
Walterpachl (talk | contribs) REXX added |
|||
Line 18: | Line 18: | ||
</pre> |
</pre> |
||
=={{header| |
=={{header|D}}== |
||
<lang |
<lang d>import std.stdio; |
||
$str .= "bar"; |
|||
void main() { |
|||
print $str, "\n";</lang> |
|||
string s = "Hello"; |
|||
s ~= " world!"; |
|||
writeln(s); |
|||
}</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre>Hello world!</pre> |
||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
Revision as of 11:40, 3 October 2013
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses
Create a string variable equal to any text value. Append the string variable with another string literal.
To illustrate the operation, show the content of the variable.
ALGOL 68
File: String_append.a68<lang algol68>#!/usr/bin/a68g --script #
- -*- coding: utf-8 -*- #
STRING str := "12345678"; str +:= "9!"; print(str)</lang>Output:
123456789!
D
<lang d>import std.stdio;
void main() {
string s = "Hello"; s ~= " world!"; writeln(s);
}</lang>
- Output:
Hello world!
Perl 6
<lang perl6>my $str = "foo"; $str ~= "bar"; say $str;</lang>
- Output:
foobar
Python
File: String_append.py<lang python>#!/usr/bin/env python
- -*- coding: utf-8 -*- #
str = "12345678"; str += "9!"; print(str)</lang>Output:
123456789!
REXX
<lang rexx>s='he' s=s'llo world!' Say s</lang> Output:
hello world!
Tcl
String concatenation is a fundamental feature of the Tcl language, and there is also an append
that makes concatenation even simpler:
<lang tcl>set s "he"
set s "${s}llo wo"; # The braces distinguish varname from text to concatenate
append s "rld"
puts $s</lang>
- Output:
hello world
Wart
<lang wart>s <- "12345678" s <- (s + "9!")</lang>