Comparison of programming languages (strings)

Programming language comparisons

* General comparison
* Assignment
* Basic syntax
* Basic instructions
* Comments
* Control flow
* Foreach loops
* While loops
* For loops
* Do-while
* Exception handling
* Enumerated types
* Generators
* Anonymous functions
* Conditional expressions
* Functional instructions
* Arrays
* Associative arrays
* Scope
* String operations
* String functions
* Higher-order functions
* Type systems
* List comprehension
* Object-oriented programming
* Object-oriented constructors
* Operators

* Evaluation strategy
* List of "Hello World" programs

* Languages with dependent types
* Comparison of type systems

* * *

Comparison of individual languages

* ALGOL 58's influence on ALGOL 60
* ALGOL 60: Comparisons with other languages
* Comparison of ALGOL 68 and C++
* ALGOL 68: Comparisons with other languages
* Compatibility of C and C++
* Comparison of Pascal and Borland Delphi
* Comparison of Object Pascal and C
* Comparison of Pascal and C
* Comparison of Java and C++
* Comparison of C# and Java
* Comparison of C# and Visual Basic .NET
* Comparison of Visual Basic and Visual Basic .NET

* v
* t
* e

This comparison of programming languages (strings) compares the features of string data structures or text-string processing for over 52 various computer programming languages.

## Contents

* 1 Concatenation
* 1.1 Common variants
* 1.2 Unique variants
* 2 String literals
* 2.1 Quoted interpolated
* 2.2 Escaped quotes
* 2.3 Dual quoting
* 2.4 Quoted raw
* 2.5 Multiline string
* 2.6 Unique quoting variants
* 3 Notes
* 4 References

## Concatenation

Different languages use different symbols for the concatenation operator. Many languages use the "+" symbol, though several deviate from this.

### Common variants

Operator  | Languages

|

\+  | ALGOL 68, BASIC, C++, C#, Cobra, Dart, Eiffel, F#, Go, Java, JavaScript, Object Pascal, Objective-C, Pascal, Python, Ruby, Rust, Scala, Swift, Turing, Windows PowerShell, Ya
++  | Erlang, Haskell
$+  | mIRC scripting language
& | Ada, AppleScript, COBOL (for literals only), Curl, FreeBASIC, Excel, Nim, Seed7, VHDL, Visual Basic, Visual Basic .NET
concatenate  | Common Lisp
.  | Autohotkey, Maple (up to version 5), Perl, PHP
~  | D, Raku, Symfony (Expression Language component)
||  | Icon, Maple (from version 6), PL/I, Rexx, Standard SQL
<> | Mathematica, Wolfram Language
..  | Lua
:  | Pick Basic
,  | APL, J, Smalltalk
^  | F#, OCaml, rc, Standard ML
//  | Fortran
*  | Julia

### Unique variants

* AWK uses the empty string: two expressions adjacent to each other are concatenated. This is called juxtaposition. Unix shells have a similar syntax. Rexx uses this syntax for concatenation including an intervening space.
* C (along with Python) allows juxtaposition for string literals, however, for strings stored as character arrays, the `strcat` function must be used.
* COBOL uses the `STRING` statement to concatenate string variables.
* MATLAB and Octave use the syntax "`[x y]`" to concatenate x and y.
* Visual Basic and Visual Basic .NET can also use the "`+`" sign but at the risk of ambiguity if a string representing a number and a number are together.
* Microsoft Excel allows both "`&`" and the function "`=CONCATENATE(X,Y)`".
* Rust has the `concat!` macro and the `format!` 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.

Syntax  | Language(s)

|

`$"hello, {name}"` | C#, Visual Basic .NET
`"Hello, $name!"` | Bourne shell, Dart, Perl, PHP, Windows PowerShell
`qq(Hello, $name!)` | Perl (alternate)
`"Hello, {$name}!"` | PHP (alternate)
`"Hello, #{name}!"` | CoffeeScript, Ruby
`%Q(Hello, #{name}!)` | Ruby (alternate)
`(format nil "Hello, ~A" name)` | Common Lisp
``Hello, ${name}!`` | JavaScript (ECMAScript 6)
`"Hello, \(name)!"` | Swift
`f'Hello, {name}!'` | Python

### Escaped quotes

"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.

Syntax  | Language(s)

|

`"I said \"Hello, world!\""` | C, C++, C#, D, Dart, F#, Java, JavaScript, Mathematica, Ocaml, Perl, PHP, Python, Rust, Swift, Wolfram Language, Ya
`'I said \'Hello, world!\''` | CoffeeScript, Dart (alternate), JavaScript (alternate), Python (alternate)
`"I said `"Hello, world!`""` | Windows Powershell
`"I said ^"Hello, world!^""` | REBOL
`{I said "Hello, world!"}` | REBOL (alternate)
`"I said, %"Hello, World!%""` | Eiffel
`!"I said \"Hello, world!\""` | FreeBASIC
`r#"I said "Hello, world!""#` | Rust (alternate)

### Dual quoting

"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.

Syntax  | Language(s)

|

`"I said ""Hello, world!"""` | Ada, ALGOL 68, COBOL, Excel, Fortran, FreeBASIC, Visual Basic (.NET)
`'I said ''Hello, world!'''` | APL, COBOL, Fortran, Object Pascal, Pascal, rc, Smalltalk, SQL

### Quoted raw

"Raw" means the compiler treats every character within the literal exactly as written, without processing any escapes or interpolations.

Syntax  | Language(s)

|

`'Hello, world!'` | APL, Bourne shell, Fortran, Object Pascal, Pascal, Perl, PHP, Pick Basic, Ruby, Smalltalk, Windows PowerShell
`q(Hello, world!)` | Perl (alternate)
`%q(Hello, world!)` | Ruby (alternate)
`R"(Hello, world!)"` | C++11
`@"Hello, world!"` | C#, F#
`r"Hello, world!"` | Cobra, D, Dart, Python, Rust
`r'Hello, world!'` | Dart (alternate)
`"Hello, world!"` | Cobol, FreeBASIC, Pick Basic
``Hello, world!`` | D, Go
`raw"Hello, world!"` | Scala
`String.raw`Hello, World!`` | JavaScript (ECMAScript 6) [1]

### 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.

Syntax  | Here
document  | Language(s)

|
|

<<EOF
I have a lot of things to say
and so little time to say them
EOF

| Yes  | Bourne shell, Perl, Ruby

<<<EOF
I have a lot of things to say
and so little time to say them
EOF

| Yes  | PHP

I have a lot of things to say
and so little time to say them

| No  | Windows Powershell

I have a lot of things to say
and so little time to say them

| No  | Eiffel

"""
I have a lot of things to say
and so little time to say them
"""

| No  | CoffeeScript, Dart, Groovy, Kotlin, Python, Swift

I have a lot of things to say
and so little time to say them

| No  | Common Lisp (all strings are multiline), Rust (all strings are multiline), Visual Basic .NET (all strings are multiline)

I have a lot of things to say
and so little time to say them

| No  | Rust

I have a lot of things to say
and so little time to say them

| No  | Lua

I have a lot of things to say
and so little time to say them

| No  | JavaScript (ECMAScript 6)

### Unique quoting variants

Syntax  | Variant name  | Language(s)

|
|

`13HHello, world!` | Hollerith notation  | Fortran 66
(indented with whitespace)  | Indented with whitespace and newlines  | YAML

## Notes

1\. ^ `String.raw``` still processes string interpolation.

## References

1\. ^ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Comparison of programming languages (strings). Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Comparison_of_programming_languages_(strings)&oldid=272498"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template