Content deleted Content added
Aadirulez8 (talk | contribs) m v2.05 - Fix errors for CW project (Reference list missing / disambiguation page with disallowed <ref>) |
|||
(213 intermediate revisions by more than 100 users not shown) | |||
Line 1:
{{ProgLangCompare}}
This '''comparison of programming languages (strings)''' compares the features of [[string (computer science)|string]] [[data structure]]s or [[text string|text-string]] processing for over 52 various computer [[programming language]]s.
== Concatenation ==
Different languages use different symbols for the concatenation operator.
===Common variants===
{| class="wikitable"
|-
! Operator
! Languages
|-
| +
| [[ALGOL 68]], [[BASIC]], [[C++]], [[C Sharp (programming language)|C#]], [[Cobra (programming language)|Cobra]], [[Dart (programming language)|Dart]], [[Eiffel (programming language)|Eiffel]], [[F Sharp (programming language)|F#]], [[Go (programming language)|Go]], [[Java (programming language)|Java]], [[JavaScript]], [[Object Pascal]], [[Objective-C]], [[Pascal (programming language)|Pascal]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[Rust (programming language)|Rust]], [[Scala (programming language)|Scala]], [[Swift (programming language)|Swift]], [[Turing (programming language)|Turing]], [[Windows PowerShell]], Ya
|-
| ++
| [[Erlang (programming language)|Erlang]], [[Haskell]]
|-
| $+
| [[mIRC scripting language]]
|-
| &
| [[Ada (programming language)|Ada]], [[AppleScript]], [[COBOL]] (for literals only), [[Curl (programming language)|Curl]], [[Microsoft Excel|Excel]], [[FreeBASIC]], [[HyperTalk]], [[Nim (programming language)|Nim]], [[Seed7]], [[VHDL]], [[Visual Basic]], [[Visual Basic .NET]]
|-
| concatenate
| [[Common Lisp]]
|-
| .
| Autohotkey, [[Maple (software)|Maple]] (up to version 5), [[Perl]], [[PHP]]
|-
| ~
| [[D (programming language)|D]], [[Raku (programming language)|Raku]], [[Symfony]] (Expression Language component)
|-
| <nowiki>||</nowiki>
| [[Icon (programming language)|Icon]], [[Maple (software)|Maple]] (from version 6), [[PL/I]], [[Rexx]], Standard [[SQL]]
|-
| <>
| [[Mathematica]], [[Wolfram Language]], [[Elixir (programming language)|Elixir]]
|-
| ..
| [[Lua (programming language)|Lua]]
|-
| :
| [[Pick Basic]]
|-
| ,
| [[APL (programming language)|APL]], [[J (programming language)|J]], [[Smalltalk]]
|-
| ^
| [[F Sharp (programming language)|F#]], [[OCaml]], [[Rc (Unix shell)|rc]], [[Standard ML]]
|-
| //
| [[Fortran]]
|-
| *
| [[Julia (programming language)|Julia]]
|}
===Unique variants===
* [[
* [[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 [[
* [[
* [[MATLAB]] and [[GNU Octave|Octave]] use the syntax "<code>[x y]</code>" to concatenate x and y.
* [[Visual Basic]] and [[Visual Basic .NET]] can also use the "<code>+</code>" sign but at the risk of ambiguity if a string representing a number and a number are 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.
== String literals ==
This section compares styles for declaring a [[string literal]].
=== Quoted interpolated ===
An expression is "interpolated" into a string when the compiler/interpreter evaluates it and inserts the result in its place.
<!-- Before you add your favorite language to this table, make sure it's not listed in another section. -->
{| class="wikitable"
|-
! Syntax
! Language(s)
|-
| <code>$"hello, {name}"</code>
| C#, Visual Basic .NET
|-
| <code>"Hello, $name!"</code>
| [[Bourne shell]], Dart, Perl, PHP, Windows PowerShell
|-
| <code>qq(Hello, $name!)</code>
| Perl (alternate)
|-
| <code>"Hello, {$name}!"</code>
| PHP (alternate)
|-
| <code>"Hello, #{name}!"</code>
| CoffeeScript, Ruby, [[Elixir (programming language)|Elixir]]
|-
| <code>%Q(Hello, #{name}!)</code>
| Ruby (alternate)
|-
| <code>(format nil "Hello, ~A" name)</code>
|[[Common Lisp]]
|-
| <code>`Hello, ${name}!`</code>
| JavaScript (ECMAScript 6)
|-
| <code>"Hello, \(name)!"</code>
| Swift
|-
| <code>f'Hello, {name}!'</code>
| Python
|}
===
"Escaped" quotes means that a 'flag' symbol is used to warn that the character after the flag is used in the string rather than ending the string.
<!-- Before you add your favorite language to this table, make sure it's not listed in another section. -->
{| class="wikitable"
|-
! Syntax
! Language(s)
|-
| <code>"I said \"Hello, world!\""</code>
| C, C++, C#, D, Dart, F#, Java, JavaScript, Mathematica, Ocaml, Perl, PHP, Python, Rust, Swift, Wolfram Language, Ya
|-
| {{nowrap|<code><nowiki>'I said \'Hello, world!\''</nowiki></code>}}
| CoffeeScript, Dart (alternate), JavaScript (alternate), Python (alternate)
|-
| <code>"I said `"Hello, world!`""</code>
| Windows Powershell
|-
| <code>"I said ^"Hello, world!^""</code>
| REBOL
|-
| <code>{I said "Hello, world!"}</code>
| REBOL (alternate)
|-
| <code>"I said, %"Hello, World!%""</code>
| Eiffel
|-
| <code>!"I said \"Hello, world!\""</code>
| FreeBASIC
|-
| {{nowrap|<code>r#"I said "Hello, world!""#</code>}}
|Rust (alternate)
|-
| {{nowrap|<code>R"("I said "Hello, world!")"</code>}}
|C++ (alternate)
|}
===
"Dual quoting" means that whenever a quote is used in a string, it is used twice, and one of them is discarded and the single quote is then used within the string.
<!-- Before you add your favorite language to this table, make sure it's not listed in another section. -->
{| class="wikitable"
|-
! Syntax
! Language(s)
|-
| <code>"I said ""Hello, world!"""</code>
| Ada, ALGOL 68, COBOL, Excel, Fortran, FreeBASIC, Visual Basic (.NET)
|-
| <code><nowiki>'I said ''Hello, world!'''</nowiki></code>
| APL, COBOL, Fortran, Object Pascal, Pascal, rc, Smalltalk, SQL
|}
===
"Raw" means the compiler treats every character within the literal exactly as written, without processing any escapes or interpolations.
<!-- Before you add your favorite language to this table, make sure it's not listed in another section. -->
{| class="wikitable"
|-
! Syntax
! Language(s)
|-
| <code>'Hello, world!'</code>
| APL, Bourne shell, Fortran, Object Pascal, Pascal, Perl, PHP, Pick Basic, Ruby, Smalltalk, Windows PowerShell
|-
| <code>q(Hello, world!)</code>
| Perl (alternate)
|-
| <code>%q(Hello, world!)</code>
| Ruby (alternate)
|-
| <code>R"(Hello, world!)"</code>
| C++11
|-
| <code>@"Hello, world!"</code>
| C#, F#
|-
| <code>r"Hello, world!"</code>
| Cobra, D, Dart, Python, Rust
|-
| <code>r'Hello, world!'</code>
| Dart (alternate)
|-
| <code>"Hello, world!"</code>
| Cobol, FreeBASIC, Pick Basic
|-
| <code>`Hello, world!`</code>
| D, Go
|-
| <code>raw"Hello, world!"</code>
| Scala
|-
| <code>String.raw`Hello, World!`</code>
| JavaScript (ECMAScript 6) {{ref|es6rawstr}}
|}
=== Multiline string ===
Many languages have a syntax specifically intended for strings with multiple lines. In some of these languages, this syntax is a [[here document]] or "heredoc": A token representing the string is put in the middle of a line of code, but the code continues after the starting token and the string's content doesn't appear until the next line. In other languages, the string's content starts immediately after the starting token and the code continues after the string literal's terminator.
<!-- Before you add your favorite language to this table, make sure it's not listed in another section. -->
{| class="wikitable" border="1"
|-
! Syntax
! Here<br/>document
! Language(s)
|-
| <pre><<EOF
I have a lot of things to say
and so little time to say them
EOF</pre>
| {{Yes}}
| Bourne shell, Perl, Ruby
|-
| <pre><<<EOF
I have a lot of things to say
and so little time to say them
EOF</pre>
| {{Yes}}
| PHP
|-
| <pre>@"
I have a lot of things to say
and so little time to say them
"@</pre>
| {{No}}
| Windows Powershell
|-
| <pre>"[
I have a lot of things to say
and so little time to say them
]"</pre>
| {{No}}
| Eiffel
|-
| <pre>"""
I have a lot of things to say
and so little time to say them
"""</pre>
| {{No}}
| CoffeeScript, Dart, 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)
|}
=== Unique quoting variants ===
<!-- Before you add your favorite language to this table, make sure it's not listed in another section. -->
{| class="wikitable"
|-
! Syntax
! Variant name
! Language(s)
|-
| <code>13HHello, world!</code>
| Hollerith notation
| Fortran 66
|-
| (indented with whitespace)
| Indented with whitespace and newlines
| 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
[[Category:String (computer science)|Programming language comparison]]
|