Comparison of programming languages (string functions): Difference between revisions

Content deleted Content added
Emanuele6 (talk | contribs)
Do not use "or" inside code blocks to list multiple options: "or" is not part of the code so it is confusing. Also split options separeted by "or" with newlines instead of "or"
m left: {{codett}}
 
(8 intermediate revisions by 6 users not shown)
Line 342:
|[[Go (programming language)|Go]]
|-
| <code>string compare ?-nocase? ?-length int? ''string<sub>1</sub>'' ''string<sub>2</sub>''</code>
|[[Tcl]]
|-
Line 395:
! Format !! Languages
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1= =, <>, <, >, <=</code>}} and <code>{{mono|1=>=</code>}}
|[[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (software)|Delphi]]), [[OCaml]], [[Seed7]], [[Standard ML]], [[BASIC]], [[Visual Basic (classic)|VB]], [[Visual Basic .NET|VB .NET]], [[F Sharp (programming language)|F#]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1= =, /=, ≠, <, >, <=, ≤</code>}} and <code>{{mono|1=</code>}}; Also: <code>{{mono|1=EQ, NE, LT, LE, GE</code>}} and <code>{{mono|1=GT</code>}}
|[[ALGOL 68]]
|-
| <code>(stringOP? ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>, where <code>OP</code> can be any of <code>{{mono|1==, -ci=, <, -ci<, >, -ci>, <=, -ci<=, >=</code>}} and <code>{{mono|1=-ci>=</code>}} (operators starting with '<code>-ci</code>' are case-insensitive)
|[[Scheme (programming language)|Scheme]]
|-
| <code>(stringOP ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>, where <code>OP</code> can be any of <code>{{mono|1==, -ci=, <>, -ci<>, <, -ci<, >, -ci>, <=, -ci<=, >=</code>}} and <code>{{mono|1=-ci>=</code>}} (operators starting with '<code>{{mono|1=-ci</code>}}' are case-insensitive)
|[[Scheme (programming language)|Scheme]] (SRFI 13)
|-
| <code>(stringOP ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>, where <code>OP</code> can be any of <code>{{mono|1==, -equal, /=, -not-equal, <, -lessp, >, -greaterp, <=, -not-greaterp, >=</code>}} and <code>{{mono|1=-not-lessp</code>}} (the verbal operators are case-insensitive)
|[[Common Lisp]]
|-
| <code>(stringOP ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>, where <code>OP</code> can be any of <code>{{mono|1==, /=, <, >, <=,</code>}} and <code>{{mono|1=>=</code>}}
|[[ISLISP]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1= =, \=, <, >, <=</code>}} and <code>{{mono|1=>=</code>}}
|[[Rexx]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1= =, ¬=, <, >, <=, >=, ¬<</code>}} and <code>{{mono|1=¬></code>}}
|[[PL/I]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1==, /=, <, >, <=</code>}} and <code>{{mono|1=>=</code>}}
|[[Ada (programming language)|Ada]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1===, /=, <, >, =<</code>}} and <code>{{mono|1=>=</code>}}
|[[Erlang (programming language)|Erlang]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1===, /=, <, >, <=</code>}} and <code>{{mono|1=>=</code>}}
|[[Haskell]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1=''eq'', ''ne'', ''lt'', ''gt'', ''le''</code>}} and <code>{{mono|1=''ge''</code>}}
|[[Perl]], [[Raku (programming language)|Raku]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1===, !=, <, >, <=</code>}} and <code>{{mono|1=>=</code>}}
|[[C++]] (STL), [[C Sharp (programming language)|C#]], [[D (programming language)|D]], [[Go (programming language)|Go]], [[JavaScript]], [[Python (programming language)|Python]], [[PHP]], [[Ruby (programming language)|Ruby]], [[Rust (programming language)|Rust]],<ref name="Rust compare">In Rust, the operators <code>{{mono|1==</code>=}} and <code>{{mono|1=!=</code>}} and the methods <code>eq</code>, <code>ne</code> are implemented by the [https://doc.rust-lang.org/std/primitive.str.html#impl-PartialEq%3Cstr%3E <code>PartialEq</code>] trait, and the operators {{mono|1=<code><</code>}}, <code>></code{{mono|1=>}}, <code>{{mono|1=<=</code>}}, <code>{{mono|1=>=</code>}} and the methods <code>lt</code>, <code>gt</code>, <code>le</code>, <code>ge</code> are implemented by the [https://doc.rust-lang.org/std/primitive.str.html#impl-PartialOrd%3Cstr%3E <code>PartialOrd</code>] trait.</ref> [[Swift (programming language)|Swift]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1=-eq, -ceq, -ne, -cne, -lt, -clt, -gt, -cgt, -le, -cle, -ge,</code>}} and <code>{{mono|1=-cge</code>}} (operators starting with '<code>{{mono|1=c</code>}}' are case-sensitive)
|[[Windows PowerShell]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1===, ~=, <, >, <=</code>}} and <code>{{mono|1=>=</code>}}
|[[Lua (programming language)|Lua]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1==, ~=, <, >, <=</code>}} and <code>{{mono|1=>=</code>}}
|[[Smalltalk]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>{{mono|1===, /=, <, >, <=</code>}} and <code>{{mono|1=>=; Also: .EQ., .NE., .LT., .LE., .GT.</code>}} and <code>{{mono|1=.GE.</code>}}
|[[Fortran]].<ref>The operators use the compiler's default collating sequence.</ref>
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code> where <code>OP</code> can be any of <code>{{mono|1==, <>, <, >, <=, >=</code>}} as well as worded equivalents
| [[COBOL]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code> where <code>OP</code> can be any of <code>{{mono|1===, <>, <, >, <=</code>}} and <code>{{mono|1=>=</code>}}
| [[Cobra (programming language)|Cobra]]
|-
Line 754:
|-
| <code>''string<sub>1</sub>'' eq ''string<sub>2</sub>''</code>
|[[Perl]], [[Raku (programming language)|Raku]], [[Tcl]]
|-
| <code>''string<sub>1</sub>''.equals(''string<sub>2</sub>'')</code>
Line 762:
|[[C Sharp (programming language)|C#]]
|-
| <code>''string<sub>1</sub>'' -eq ''string<sub>2</sub>''</code><br><code>[string]::Equals(''string<sub>1</sub>'', ''string<sub>2</sub>'')</code>
|[[Windows PowerShell]]
|-
Line 1,584:
! Format !! Languages
|-
|<code>{{codett|string (string'First .. string'First +|ada}} ''n'' - 1)</code>
|[[Ada (programming language)|Ada]]
|-
Line 1,605:
|[[Objective-C]] (<code>NSString *</code> only)
|-
| <code>{{codett|(apply str (take|clojure}} ''n'' ''string''))</code>
|[[Clojure]]
|-
Line 3,013:
|[[C (programming language)|C]] (operates on one character)
|-
|<code>{{codett|2=c|1=for(size_t i = 0, len = strlen(}}''string''); i&lt; len; i++) ''string''[i] = toupper(''string''[i]);</code><br><code>{{codett|2=c|1=for (char *c =}} ''string''{{codett|2=c|1=; *c != '\0'; c++) *c = toupper(*c);}}</code>
|[[C (programming language)|C]] (string / char array)
|-
Line 3,069:
| <code>''string''.toUpperCase()</code>
|[[Java (programming language)|Java]], [[JavaScript]]
|-
| <code>''string''.uppercase()</code>
|[[Kotlin (programming language)|Kotlin]]<ref>{{cite web |title=uppercase - Kotlin Programming Language |url=https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/uppercase.html |website=Kotlin |access-date=9 November 2024 |language=en}}</ref>
|-
| <code>to_upper(''string'')</code>
Line 3,165 ⟶ 3,168:
|[[Factor (programming language)|Factor]]
|-
| <code>{{codett|(string-trim '(#\Space #\Tab #\Newline)|lisp}} ''string'')</code>
|[[Common Lisp]]
|-
Line 3,201 ⟶ 3,204:
|[[PHP]], [[Raku (programming language)|Raku]]
|-
| <code>[''string'' {{codett|stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]|objc}}</code>
|[[Objective-C]] using [[Cocoa (API)|Cocoa]]
|-
| <code>''string'' withBlanksTrimmed</code><br><code>''string'' withoutSpaces</code><br><code>''string'' withoutSeparators</code>
|[[Smalltalk]] ([[Squeak]], [[Pharo]])<br>[[Smalltalk]]
|-
|<code>strip(string)</code>
|[[SAS System(software)|SAS]]
|-
|<code>string trim ''$string''</code>