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>var str, str1 = "String"
<lang nim>let str = "String"
echo(str & " literal.")
echo str & " literal."
str1 = str1 & " literal."
echo(str1)


# -> String literal.</lang>
# -> String literal.</lang>


Strings can be concatenated as arrays and joined with a separating characters:
Strings can be concatenated as arrays and joined with separating characters:
<lang nim>var str1 = "String"
<lang nim>import strutils
var str = "String"
echo(join([str1, " literal.", "HelloWorld!"], "~~"))
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>var str1 = "String"
<lang nim>import strutils
echo "$# $# $#" % [str1, "literal.", "HelloWorld!"]


var str = "String"
# -> String literal. HelloWorld!</lang>
echo "$# $# $#" % [str, "literal.", "HelloWorld!"]
# -> String literal. HelloWorld!

# Alternate form providing automatic conversion of arguments to strings.
echo "$# $# $#".format(str, 123, "HelloWorld!")
# -> String 123 HelloWorld!


=={{header|NS-HUBASIC}}==
=={{header|NS-HUBASIC}}==