String concatenation: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
(Simplified first example. Added missing "import strutils". Added example with "format".) |
||
Line 1,321: | Line 1,321: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
Strings can be concatenated with <code>&</code>. |
Strings can be concatenated with <code>&</code>. |
||
<lang nim> |
<lang nim>let str = "String" |
||
echo |
echo str & " literal." |
||
str1 = str1 & " literal." |
|||
echo(str1) |
|||
# -> String literal.</lang> |
# -> String literal.</lang> |
||
Strings can be concatenated as arrays and joined with |
Strings can be concatenated as arrays and joined with separating characters: |
||
<lang nim> |
<lang nim>import strutils |
||
var str = "String" |
|||
echo |
echo join([str, " literal.", "HelloWorld!"], "~~") |
||
# -> String~~ literal.~~HelloWorld!</lang> |
# -> String~~ literal.~~HelloWorld!</lang> |
||
Strings can be combined using string formatting: |
Strings can be combined using string formatting: |
||
<lang nim> |
<lang nim>import strutils |
||
⚫ | |||
var str = "String" |
|||
⚫ | |||
⚫ | |||
⚫ | |||
# Alternate form providing automatic conversion of arguments to strings. |
|||
echo "$# $# $#".format(str, 123, "HelloWorld!") |
|||
# -> String 123 HelloWorld! |
|||
=={{header|NS-HUBASIC}}== |
=={{header|NS-HUBASIC}}== |