Comparison of programming languages (strings): Difference between revisions

Content deleted Content added
1011X (talk | contribs)
correct text for Rust
m v2.05 - Fix errors for CW project (Reference list missing / disambiguation page with disallowed <ref>)
 
(28 intermediate revisions by 20 users not shown)
Line 1:
{{Unreferenced|date=February 2009}}
{{ProgLangCompare}}
 
Line 8 ⟶ 7:
 
===Common variants===
 
{| class="wikitable"
|-
Line 15 ⟶ 13:
|-
| +
| [[ALGOL 68]], [[BASIC programming language|BASIC]], [[C++]], [[C Sharp (programming language)|C#]], [[Cobra (programming language) |Cobra]], [[PascalDart (programming language)|PascalDart]], [[ObjectEiffel Pascal(programming language)|Eiffel]], [[EiffelF Sharp (programming language)|EiffelF#]], [[Go (programming language)|Go]], [[JavaScript]], [[Java (programming language)|Java]], [[PythonJavaScript]], [[Object Pascal]], [[Objective-C]], [[Pascal (programming language)|PythonPascal]], [[TuringPython (programming language)|TuringPython]], [[Ruby (programming language)|Ruby]], [[Rust (programming language)|Rust]], [[WindowsScala PowerShell]],(programming [[Objective-Clanguage)|Scala]], [[Swift (programming language)|Swift]], [[F SharpTuring (programming language)|F#Turing]], [[ScalaWindows (programming language)|ScalaPowerShell]], Ya
|-
| ++
| [[HaskellErlang (programming language)|HaskellErlang]], [[Erlang (programming language)|ErlangHaskell]]
|-
| $+
| [[MIRCmIRC scripting language|mIRC Scripting Language]]
|-
| &
| [[Ada (programming language)|Ada]], [[AppleScript]], [[COBOL]] (for literals only), [[Curl (programming language)|Curl]], [[Seed7Microsoft Excel|Excel]], [[VHDLFreeBASIC]], [[Visual BasicHyperTalk]], [[MicrosoftNim Excel(programming language)|ExcelNim]], [[FreeBASICSeed7]], [[VHDL]], [[Visual Basic]], [[Visual Basic .NET]]
|-
| concatenate
| nconc
| [[Common Lisp]]
|-
| .
| Autohotkey, [[PerlMaple (software)|Maple]] (beforeup to version 65), [[PHPPerl]], and [[Maple computer algebra system|MaplePHP]] (up to version 5), Autohotkey
|-
| ~
| [[PerlD 6(programming language)|D]] and, [[DRaku (programming language)|DRaku]], [[Symfony]] (Expression Language component)
|-
| <nowiki>||</nowiki>
| [[Icon (programming language)|Icon]], Standard [[SQLMaple (software)|Maple]] (from version 6), [[PL/I]], [[Rexx]], andStandard [[Maple computer algebra system|MapleSQL]] (from version 6)
|-
| <>
| [[Mathematica]], [[Wolfram Language]], [[Elixir (programming language)|Elixir]]
|-
| ..
| [[Lua (programming language)|Lua]]
|-
| :
| [[Pick Basic]]
|-
| ,
| [[JAPL (programming language)|APL]], [[Smalltalk]], [[APLJ (programming language)|APLJ]], [[Smalltalk]]
|-
| ^
| [[OCamlF Sharp (programming language)|F#]], [[Standard MLOCaml]], [[F SharpRc (programmingUnix languageshell)|F#rc]], [[rcStandard ML]]
|-
| //
Line 62 ⟶ 60:
===Unique variants===
 
* [[AwkAWK]] uses the empty string: two expressions adjacent to each other are concatenated. This is called [[Juxtaposition (literary)|juxtaposition]]. [[Unix shell]]s have a similar syntax. [[Rexx]] uses this syntax for concatenation including an intervening space.
* [[C (programming language)|C]] (along with [[Python (programming language)|Python]] and [[Dart (programming language)|Dart]]<ref>{{Cite web |title=Built-in types |url=https://dart.dev/language/built-in-types/ |access-date=2025-07-22 |website=dart.dev |language=en}}</ref>) allows juxtaposition for string literals, however, for strings stored as [[Character (computing)|character]] [[Array data structure|arrays]], the <code>[[strcat]]</code> function must be used.
* [[COBOL]] uses the <code>STRING</code> statement to concatenate string variables.
* [[MATLAB]] and [[GNU Octave programming language|Octave]] use the syntax "<code>[x y]</code>" to concatenate x and y.
* [[Visual Basic]] Versionsand 1[[Visual toBasic 6.NET]] can also use the "<code>+</code>" sign but, thisat leadsthe risk toof ambiguity if a string representing a number and a number is addedare together.
* [[Microsoft Excel]] allows both "<code>&</code>" and the function "<code>=CONCATENATE(X,Y)</code>".
* [[Rust (programming language)|Rust]] has the <code>concat!</code> macro and the <code>format!</code> macro, of which the latter is the most prevalent throughout the documentation and examples.
Line 81 ⟶ 79:
! Language(s)
|-
| <ttcode>$"hello, {name}"</ttcode>
| C#, Visual Basic .NET
| C#
|-
| <ttcode>"Hello, $name!"</ttcode>
| [[Bourne shell]], Dart, Perl, PHP, Windows PowerShell
|-
| <ttcode>qq(Hello, $name!)</ttcode>
| Perl (alternate)
|-
| <ttcode>"Hello, {$name}!"</ttcode>
| PHP (alternate)
|-
| <ttcode>"Hello, #{name}!"</ttcode>
| CoffeeScript, Ruby, [[Elixir (programming language)|Elixir]]
|-
| <ttcode>%Q(Hello, #{name}!)</ttcode>
| Ruby (alternate)
|-
| <ttcode>(format tnil "Hello, ~A" name)</ttcode>
|[[Common Lisp]]
|-
| <ttcode>`Hello, ${name}!`</ttcode>
| JavaScript (ECMAScript 6)
|-
| <ttcode>"Hello, \(name)!"</ttcode>
| Swift
|-
| <ttcode>f'Hello, {name}!'</ttcode>
| Python
|}
Line 120 ⟶ 118:
! Language(s)
|-
| <ttcode>"I said \"Hello, world!\""</ttcode>
| C, C++, C#, D, Dart, F#, Java, JavaScript, Mathematica, Ocaml, Perl, PHP, Python, Rust, Swift, Wolfram Language, Ya
|-
| {{nowrap|<ttcode><nowiki>'I said \'Hello, world!\''</nowiki></ttcode>}}
| CoffeeScript, Dart (alternate), JavaScript (alternate), Python (alternate)
|-
| <ttcode>"I said `"Hello, world!`""</ttcode>
| Windows Powershell
|-
| <ttcode>"I said ^"Hello, world!^""</ttcode>
| REBOL
|-
| <ttcode>{I said "Hello, world!"}</ttcode>
| REBOL (alternate)
|-
| <ttcode>"I said, %"Hello, World!%""</ttcode>
| Eiffel
|-
| <ttcode>!"I said \"Hello, world!\""</ttcode>
| FreeBASIC
|-
| {{nowrap|<ttcode>r#"I said "Hello, world!""#</ttcode>}}
|Rust (alternate)
|-
| {{nowrap|<code>R"("I said "Hello, world!")"</code>}}
|C++ (alternate)
|}
 
Line 153 ⟶ 154:
! Language(s)
|-
| <ttcode>"I said ""Hello, world!"""</ttcode>
| Ada, ALGOL 68, COBOL, Excel, Fortran, FreeBASIC, Visual Basic, FreeBASIC, COBOL(.NET)
|-
| <ttcode><nowiki>'I said ''Hello, world!'''</nowiki></ttcode>
| Fortran, rcAPL, COBOL, SQLFortran, Object Pascal, Object Pascal, APLrc, Smalltalk, SQL
|}
 
Line 168 ⟶ 169:
! Language(s)
|-
| <ttcode>'Hello, world!'</ttcode>
| APL, Bourne shell, Fortran, Object Pascal, Pascal, Perl, PHP, Pick Basic, Ruby, Smalltalk, Windows PowerShell, Smalltalk
|-
| <ttcode>q(Hello, world!)</ttcode>
| Perl (alternate)
|-
| <ttcode>%q(Hello, world!)</ttcode>
| Ruby (alternate)
|-
| <ttcode>R"(Hello, world!)"</ttcode>
| C++11
|-
| <ttcode>@"Hello, world!"</ttcode>
| C#, F#
|-
| <ttcode>r"Hello, world!"</ttcode>
| Cobra, D, Dart, Python, Rust
|-
| <ttcode>"r'Hello, world!"'</ttcode>
| Dart (alternate)
|-
| <code>"Hello, world!"</code>
| Cobol, FreeBASIC, Pick Basic
|-
| <ttcode>`Hello, world!`</ttcode>
| D, Go
|-
| <ttcode>raw"Hello, world!"</ttcode>
| Scala
|-
| <code>String.raw`Hello, World!`</code>
| JavaScript (ECMAScript 6) {{ref|es6rawstr}}
|}
 
Line 202 ⟶ 209:
|-
! Syntax
! Here <br/>document
! Language(s)
|-
| <pre><<EOF
| <tt><<EOF<br />I have a lot of things to say<br />and so little time to say them<br />EOF</tt>
I have a lot of things to say
| Yes
and so little time to say them
| Bourne shell, Perl, PHP, Ruby
EOF</pre>
| {{Yes}}
| Bourne shell, Perl, PHP, Ruby
|-
| <ttpre><<<EOF<br />
I have a lot of things to say<br />
and so little time to say them<br />
EOF</ttpre>
| {{Yes}}
| PHP
|-
| <pre>@"
| <tt>@"<br />I have a lot of things to say<br />and so little time to say them<br />"@</tt>
I have a lot of things to say
| No
and so little time to say them
"@</pre>
| {{No}}
| Windows Powershell
|-
| <pre>"[
| <tt>"[<br />I have a lot of things to say<br />and so little time to say them<br />]"</tt>
I have a lot of things to say
| No
and so little time to say them
]"</pre>
| {{No}}
| Eiffel
|-
| <pre>"""
| <tt>"""<br />I have a lot of things to say<br />and so little time to say them<br />"""</tt>
I have a lot of things to say
| No
and so little time to say them
| CoffeeScript, Python, Groovy, Swift
"""</pre>
| {{No}}
| CoffeeScript, PythonDart, Groovy, Kotlin, Python, Swift
|-
|<pre>"
I have a lot of things to say
and so little time to say them
"</pre>
| {{No}}
|[[Common Lisp]] (all strings are multiline), Rust (all strings are multiline), Visual Basic .NET (all strings are multiline)
|-
| <pre>R"(
I have a lot of things to say
and so little time to say them
)"
</pre>
| {{No}}
| C#++
|-
| <pre>r"
I have a lot of things to say
and so little time to say them
"</pre>
| {{No}}
| Rust
|-
| <pre>[[
I have a lot of things to say
and so little time to say them
]]</pre>
| {{No}}
| Lua
|-
| <pre>`
I have a lot of things to say
and so little time to say them
`</pre>
| {{No}}
| JavaScript (ECMAScript 6)
|}
 
Line 234 ⟶ 292:
! Language(s)
|-
| <ttcode>13HHello, world!</ttcode>
| Hollerith notation
| Fortran 66
Line 242 ⟶ 300:
| YAML
|}
 
== Notes ==
:1. {{note|es6rawstr}} <code>String.raw``</code> still processes string interpolation.
 
==References==
{{Reflist}}
:1. {{note|es6rawstr}} https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw
 
[[Category:Programming language comparisons|*Strings]]