Jump to content

String concatenation: Difference between revisions

Simplified first example. Added missing "import strutils". Added example with "format".
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:
=={{header|Nim}}==
Strings can be concatenated with <code>&</code>.
<lang nim>varlet str, str1 = "String"
echo( str & " literal.")
str1 = str1 & " literal."
echo(str1)
 
# -> String literal.</lang>
 
Strings can be concatenated as arrays and joined with a separating characters:
<lang nim>varimport str1 = "String"strutils
var str = "String"
echo( join([str1str, " literal.", "HelloWorld!"], "~~"))
 
# -> String~~ literal.~~HelloWorld!</lang>
 
Strings can be combined using string formatting:
<lang nim>varimport str1 = "String"strutils
echo "$# $# $#" % [str1, "literal.", "HelloWorld!"]
 
var str = "String"
# -> String literal. HelloWorld!</lang>
echo "$# $# $#" % [str1str, "literal.", "HelloWorld!"]
# -> String literal. HelloWorld!</lang>
 
# Alternate form providing automatic conversion of arguments to strings.
echo "$# $# $#".format(str, 123, "HelloWorld!")
# -> String 123 HelloWorld!
 
=={{header|NS-HUBASIC}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.