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

Content deleted Content added
m Find character: {{mono}}
m left: {{codett}}
 
(25 intermediate revisions by 12 users not shown)
Line 1:
{{Short description|none}}
{{redirectRedirect|String functions|string functions in formal language theory|String operations}}
{{furtherFurther|Comparison of programming languages}}
<!--
NOTE TO CONTRIBUTORS:
##################################
Thanks to all who have submitted code samples from various programming languages. When adding code samples, *please* include no extraneous characters or symbols that are not part of a programming language, such as interactive command prompts. This can needlessly confuse general readers.
NOTE TO CONTRIBUTORS:
Thanks to all who have submitted code samples from various programming languages.
When adding code samples, *please* do not include extraneous characters or symbols
that are not part of a programming language, such as interactive command prompts.
This causes unneeded confusion for general readers.
 
All code samples should at least be able to compile without error, when copied and pasted directly cutinto a source code file.
and pasted into a source code file.
##################################
-->
{{ProgLangCompare}}
Line 35 ⟶ 30:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>charAt(string,integer)</code> returns character.
|-
Line 49 ⟶ 44:
|-
| <code>''string''[''i'']</code>
|[[ALGOL 68]], [[APL (programming language)|APL]], [[Julia (programming language)|Julia]], [[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]]), [[Seed7]]
|1
|-
Line 101 ⟶ 96:
|-
| <code>''string'' !! ''i''</code>
|[[Haskell (programming language)|Haskell]]
|0
|-
Line 121 ⟶ 116:
|-
| <code>substr(''string'', ''i'', 1)</code>
|[[Perl 5]] 5<ref name="at1"/>
|0
|-
| <code>substr(''string'', ''i'', 1)</code> <br /> <code>string.substr(''i'', 1)</code>
|[[Raku (programming language)|Raku]]<ref name="at2"/>
|0
Line 144 ⟶ 139:
|0
|-
| <code>string.sub(''string'', ''i'', ''i'') <br /code><br><code> (''string''):sub(''i'', ''i'')</code>
|[[Lua (programming language)|Lua]]<ref name="at1"/>
|1
Line 179 ⟶ 174:
<syntaxhighlight lang="pascal">
{ Example in Pascal }
var
MyStr: string = 'Hello, World';
MyChar: Char;
Line 259 ⟶ 254:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>compare(string<sub>1</sub>,string<sub>2</sub>)</code> returns integer.
|-
Line 267 ⟶ 262:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>IF ''string<sub>1</sub>''<''string<sub>2</sub>'' THEN -1 ELSE ABS (''string<sub>1</sub>''>''string<sub>2</sub>'') FI</code>
Line 285 ⟶ 280:
|-
| <code>StrComp(''string<sub>1</sub>'', ''string<sub>2</sub>'')</code>
|[[Visual Basic (classic)|VB]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
|-
| <code>''string<sub>1</sub>'' cmp ''string<sub>2</sub>''</code>
Line 303 ⟶ 298:
|-
| <code>CompareStr(''string<sub>1</sub>'', ''string<sub>2</sub>'')</code>
|[[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
|-
| <code>''string<sub>1</sub>''.compareTo(''string<sub>2</sub>'')</code>
Line 330 ⟶ 325:
|-
| <code>compare ''string<sub>1</sub>'' ''string<sub>2</sub>''</code>
|[[Haskell (programming language)|Haskell]]<ref>returns LT, EQ, or GT</ref>
|-
| <code>[string]::Compare(''string<sub>1</sub>'', ''string<sub>2</sub>'')</code>
Line 338 ⟶ 333:
|[[Objective-C]] (<code>NSString *</code> only)
|-
| <code>LLT(''string<sub>1</sub>'',''string<sub>2</sub>'') <br/code><br><code> LLE(''string<sub>1</sub>'',''string<sub>2</sub>'') <br/code><br><code> LGT(''string<sub>1</sub>'',''string<sub>2</sub>'') <br/code><br><code> LGE(''string<sub>1</sub>'',''string<sub>2</sub>'') </code>
|[[Fortran]]<ref>returns <code>.TRUE.</code> or <code>.FALSE.</code>. These functions are based on the ASCII collating sequence.</ref>
|-
Line 347 ⟶ 342:
|[[Go (programming language)|Go]]
|-
| <code>string compare ?-nocase? ?-length int? ''string<sub>1</sub>'' ''string<sub>2</sub>''</code>
|[[Tcl]]
|-
Line 375 ⟶ 370:
 
<syntaxhighlight lang="rexx">
/** Example in Rexx */
compare("hello", "world") /* returns index of mismatch: 1 */
</syntaxhighlight>
Line 390 ⟶ 385:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>string<sub>1</sub> OP string<sub>2</sub></code> OR <code>(compare string<sub>1</sub> string<sub>2</sub>)</code> returns Boolean.
|-
Line 398 ⟶ 393:
{| class="wikitable sortable"
|- style="text-align:left;"
! 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 (programming languagesoftware)|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 (programming language)|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 492 ⟶ 487:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>concatenate(string<sub>1</sub>,string<sub>2</sub>)</code> returns string.
|-
Line 501 ⟶ 496:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>''string<sub>1</sub>'' & ''string<sub>2</sub>''</code>
Line 513 ⟶ 508:
|-
| <code>''string<sub>1</sub>'' + ''string<sub>2</sub>''</code>
|[[ALGOL 68]], [[C++]] (STL), [[C Sharp (programming language)|C#]], [[Cobra (programming language)|Cobra]], [[FreeBASIC]], [[Go (programming language)|Go]], [[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]]), [[Java (programming language)|Java]], [[JavaScript]], [[Windows PowerShell]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[Rust (programming language)|Rust]],<ref>In Rust, the <code>+</code> operator is implemented by the [https://doc.rust-lang.org/stable/std/string/struct.String.html#impl-Add%3C%26%27_%20str%3E <code>Add</code>] trait.</ref> [[F Sharp (programming language)|F#]], [[Swift (programming language)|Swift]], [[Turing (programming language)|Turing]], [[Visual Basic (classic)|VB]]
|-
| <code>''string<sub>1</sub>'' ~ ''string<sub>2</sub>''</code>
Line 534 ⟶ 529:
|-
| <code>''string<sub>1</sub>'' ++ ''string<sub>2</sub>''</code>
|[[Erlang (programming language)|Erlang]], [[Haskell (programming language)|Haskell]]
|-
| <code>''string<sub>1</sub>'' ^ ''string<sub>2</sub>''</code>
Line 606 ⟶ 601:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>contains(''string'',''substring'')</code> returns boolean
|-
Line 623 ⟶ 618:
|-
| <code>''ContainsStr''(''string'', ''substring'')</code>
| [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
|-
| <code>strstr(''string'', ''substring'') != NULL</code>
Line 656 ⟶ 651:
|-
| <code>Data.List.isInfixOf ''substring'' ''string''</code>
|[[Haskell (programming language)|Haskell]] (GHC 6.6+)
|-
| <code>''string'' includesSubstring: ''substring''</code>
Line 732 ⟶ 727:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>''string<sub>1</sub>'' == ''string<sub>2</sub>''</code>
|[[Python (programming language)|Python]], [[C++]] (STL), [[C Sharp (programming language)|C#]], [[Cobra (programming language)|Cobra]], [[Go (programming language)|Go]], [[JavaScript]] (similarity), [[PHP]] (similarity), [[Ruby (programming language)|Ruby]], [[Rust (programming language)|Rust]],<ref name="Rust compare" /> [[Erlang (programming language)|Erlang]], [[Haskell (programming language)|Haskell]], [[Lua (programming language)|Lua]], [[D (programming language)|D]], [[Mathematica]], [[Swift (programming language)|Swift]]
|-
| <code>''string<sub>1</sub>'' === ''string<sub>2</sub>''</code>
|[[JavaScript]], [[PHP]]
|-
| <code>''string<sub>1</sub>'' == ''string<sub>2</sub>'' or <br/code><br><code> ''string<sub>1</sub>'' .EQ. ''string<sub>2</sub>''</code>
|[[Fortran]]
|-
Line 753 ⟶ 748:
|-
| <code>''string<sub>1</sub>'' = ''string<sub>2</sub>''</code>
|[[ALGOL 68]], [[Ada (programming language)|Ada]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]]), [[OCaml]], [[Pascal (programming language)|Pascal]], [[Rexx]], [[Seed7]], [[Standard ML]], [[BASIC]], [[Visual Basic (classic)|VB]], [[Visual Basic .NET|VB .NET]], [[F Sharp (programming language)|F#]], [[Smalltalk]], [[PL/I]], [[COBOL]]
|-
| <code>test ''string<sub>1</sub>'' = ''string<sub>2</sub>'', or <br /code><br><code>[ ''string<sub>1</sub>'' = ''string<sub>2</sub>'' ]</code>
|[[Bourne Shell]]
|-
| <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 767 ⟶ 762:
|[[C Sharp (programming language)|C#]]
|-
| <code>''string<sub>1</sub>'' -eq ''string<sub>2</sub>'', or <br /code><br><code>[string]::Equals(''string<sub>1</sub>'', ''string<sub>2</sub>'')</code>
|[[Windows PowerShell]]
|-
| <code>[''string<sub>1</sub>'' isEqualToString:''string<sub>2</sub>''], or <br /code><br><code>[''string<sub>1</sub>'' isEqual:''string<sub>2</sub>'']</code>
|[[Objective-C]] (<code>NSString *</code> only)
|-
Line 818 ⟶ 813:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>find(''string'',''substring'')</code> returns integer
|-
Line 824 ⟶ 819:
| Returns the position of the start of the first occurrence of ''substring'' in ''string''. If the ''substring'' is not found most of these routines return an invalid index value – -1 where indexes are 0-based, 0 where they are 1-based – or some value to be interpreted as Boolean FALSE.
|-
|! Related
| instrrev
|}
Line 848 ⟶ 843:
|-
| <code>index(''string'',''substring''«,''startpos''»)</code>
|[[Perl 5]] 5
|returns −1
|-
| <code>index(''string'',''substring''«,''startpos''»)</code> <br /> <code>''string''.index(''substring'',«,''startpos''»)</code>
|[[Raku (programming language)|Raku]]
|returns Nil
Line 884 ⟶ 879:
|-
| <code>pos(''substring'', ''string'')</code>
|[[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
|returns 0
|-
Line 931 ⟶ 926:
|-
| <code>List.findIndex (List.isPrefixOf ''substring'') (List.tails ''string'')</code>
|[[Haskell (programming language)|Haskell]] (returns Justonly ''index'')
|returns Nothing
|-
Line 946 ⟶ 941:
|returns NSNotFound
|-
| <code>string.find(''string'', ''substring'') <br /code><br><code> (''string''):find(''substring'')</code>
|[[Lua (programming language)|Lua]]
|returns nil
|-
| <code>''string'' indexOfSubCollection: ''substring'' startingAt: ''startpos'' ifAbsent: ''aBlock'' <br /code><br><code> ''string'' findString: ''substring'' startingAt: ''startpos'' </code>
|[[Smalltalk]] ([[Squeak]], [[Pharo]])
|evaluate aBlock which is a block closure (or any object understanding value) <br /> returns 0
|-
| <code>startpos = INDEX(''string'', ''substring'' «,''back''» «, ''kind''»)</code>
Line 987 ⟶ 982:
|}
 
// '''Examples in C#'''
<syntaxhighlight lang="lisp">
; Examples in* Common Lisp
*: <syntaxhighlight lang="lisp">
(search "e" "Hello mate") ; returns 1
(search "z" "word") ; returns NIL
</syntaxhighlight>
* C#
 
*: <syntaxhighlight lang="csharp">
// Examples in C#
"Hello mate".IndexOf("e"); // returns 1
"Hello mate".IndexOf("e", 4); // returns 9
"word".IndexOf("z"); // returns -1
</syntaxhighlight>
* Raku
 
*: <syntaxhighlight lang="perl6raku">
# Examples in Raku
"Hello, there!".index('e') # returns 1
"Hello, there!".index('z') # returns Nil
</syntaxhighlight>
* Scheme
 
*: <syntaxhighlight lang="scheme">
; Examples in Scheme
(use-modules (srfi srfi-13))
(string-contains "Hello mate" "e") ; returns 1
(string-contains "word" "z") ; returns #f
</syntaxhighlight>
* Visual Basic
 
*: <syntaxhighlight lang="vbnet">
' Examples in Visual Basic
InStr("Hello mate", "e") ' returns 2
InStr(5, "Hello mate", "e") ' returns 10
InStr("word", "z") ' returns 0
</syntaxhighlight>
* Smalltalk
 
*: <syntaxhighlight lang="smalltalk">
" Examples in Smalltalk "
'Hello mate' indexOfSubCollection:'ate' "returns 8"
</syntaxhighlight>
*: <syntaxhighlight lang="smalltalk">
'Hello mate' indexOfSubCollection:'late' "returns 0"
</syntaxhighlight>
I'Hello mate'
*: <syntaxhighlight lang="smalltalk">
I'Hello mate'
indexOfSubCollection:'late'
ifAbsent:[ 99 ] "returns 99"
</syntaxhighlight>
'Hello mate'
*: <syntaxhighlight lang="smalltalk">
'Hello mate'
indexOfSubCollection:'late'
ifAbsent:[ self error ] "raises an exception"
Line 1,038 ⟶ 1,036:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>find_character(''string'',''char'')</code> returns integer
|-
Line 1,096 ⟶ 1,094:
|-
| <code>List.elemIndex ''char'' ''string''</code>
|[[Haskell (programming language)|Haskell]] (returns <code>Just ''index''</code>)
|returns {{mono|Nothing}}
|-
Line 1,103 ⟶ 1,101:
|raises {{mono|Not_found}}
|-
| <code>position = SCAN (''string'', ''set'' «, ''back''» «, ''kind''») or <br/code><br><code> position = VERIFY (''string'', ''set'' «, ''back''» «, ''kind''»){{ref|Fortran find|[a]}}</code>
|[[Fortran]]
|returns zero
|-
| <code>''string'' indexOf: ''char'' ifAbsent: aBlock </code><br> <code>''string'' indexOf: ''char'' </code><br> <code>''string'' includes: ''char''</code>
|[[Smalltalk]]
|evaluate <code>aBlock</code> which is a <code>BlockClosure</code> (or any object understanding value) <br> returns 0 <br> returns <code>true</code> or <code>false</code>
|-
| <code>index(''string'', ''char'', ''startpos'' )</code>
Line 1,155 ⟶ 1,153:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>format(''formatstring'', ''items'')</code> returns string
|-
Line 1,163 ⟶ 1,161:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format
! Languages
! Format string syntax
Line 1,177 ⟶ 1,175:
| <code>[[sprintf]](''formatstring'', ''items'')</code>
|[[Perl]], [[PHP]], [[Raku (programming language)|Raku]], [[Ruby (programming language)|Ruby]]
|[[C (programming language)|C]]
|C
|-
| <code>item.fmt(''formatstring'')</code>
|[[Raku (programming language)|Raku]]
|[[C (programming language)|C]]
|C
|-
| <code>io_lib:format(''formatstring'', ''items'')</code>
Line 1,189 ⟶ 1,187:
| <code>[[sprintf]](''outputstring'', ''formatstring'', ''items'')</code>
|[[C (programming language)|C]]
|[[C (programming language)|C]]
|C
|-
| <code>std::format(''formatstring'', ''items'')</code>
Line 1,197 ⟶ 1,195:
| <code>std.string.format(''formatstring'', ''items'')</code>
|[[D (programming language)|D]]
|[[C (programming language)|C]]
|C
|-
| <code>Format(''formatstring'', ''items'')</code>
|[[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
| <code></code>
|-
| <code>fmt.Sprintf(''formatstring'', ''items'')</code>
|[[Go (programming language)|Go]]
|[[C (programming language)|C]]
|C
|-
| <code>[[printf (Unix)|printf]] ''formatstring'' ''items''</code>
|[[Unix]]
|[[C (programming language)|C]]
|C
|-
| <code>''formatstring'' % (''items'')</code>
|[[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]]
|[[C (programming language)|C]]
|C
|-
| <code>''formatstring''.format(''items'')</code>
|[[Python scripting language|Python]]
|[[.NET]]
|-
|<code>f''formatstring''</code>
Line 1,224 ⟶ 1,222:
| <code>Printf.sprintf ''formatstring''</code><ref>''<code>formatstring</code>'' must be a fixed literal at compile time for it to have the correct type.</ref><code> ''items''</code>
| [[OCaml]], [[F Sharp (programming language)|F#]]
|[[C (programming language)|C]]
|C
|-
| <code>Text.Printf.printf ''formatstring'' ''items''</code>
|[[Haskell (programming language)|Haskell]] (GHC)
|[[C (programming language)|C]]
|C
|-
| <code>''formatstring'' printf: ''items''</code>
|[[Smalltalk]]
|[[C (programming language)|C]]
|C
|-
| <code>String.format(''formatstring'', ''items'')</code>
|[[Java (programming language)|Java]]
|[[C (programming language)|C]]
|C
|-
| <code>String.Format(''formatstring'', ''items'')</code>
|[[Visual Basic .NET|VB .NET]], [[C Sharp (programming language)|C#]], [[F Sharp (programming language)|F#]]
|[[.NET]]
|-
| <code>(format ''formatstring'' ''items'')</code>
Line 1,256 ⟶ 1,254:
| <code>''formatstring'' -f ''items''</code>
|[[Windows PowerShell]]
|[[.NET]]
|-
| <code>[NSString stringWithFormat:''formatstring'', ''items'']</code>
|[[Objective-C]] (<code>NSString *</code> only)
|[[C (programming language)|C]]
|C
|-
| <code>String(format:''formatstring'', ''items'')</code>
|[[Swift (programming language)|Swift]] (Foundation)
|[[C (programming language)|C]]
|C
|-
| <code>string.format(''formatstring'', ''items'') <br /code><br><code> (''formatstring''):format(''items'')</code>
|[[Lua (programming language)|Lua]]
|[[C (programming language)|C]]
|C
|-
| <code>WRITE (''outputstring'', ''formatstring'') ''items''</code>
Line 1,280 ⟶ 1,278:
| <code>String.format(''formatstring'', ''items'')</code>
|[[Cobra (programming language)|Cobra]]
|[[.NET]]
|-
| <code>format ''formatstring items''</code>
|[[Tcl]]
|[[C (programming language)|C]]
|C
|-
| <code>''formatnumbers'' ⍕ ''items''</code> or <br><code>''formatstring'' ⎕FMT ''items''</code>
|[[APL (programming language)|APL]]
|APL
|-
| <code>format!(''formatstring'', ''items'')</code>
| [[Rust (programming language)|Rust]]<ref>See [https://doc.rust-lang.org/stable/std/macro.format.html <code>std::format</code>], which is imported by the Rust [https://doc.rust-lang.org/stable/std/prelude/index.html prelude] so that it can be used under the name <code>format</code>.</ref>
| Python
|}
Line 1,320 ⟶ 1,318:
"My %s costs $%.2f" % ("pen", 19.99); # returns "My pen costs $19.99"
"My {0} costs ${1:.2f}".format("pen", 19.99); # returns "My pen costs $19.99"
</syntaxhighlight>
<syntaxhighlight lang="python3">
#Example in Python 3.6+
pen = "pen"
f"My {pen} costs {19.99}" #returns "My pen costs 19.99"
</syntaxhighlight>

<syntaxhighlight lang="scheme">
; Example in Scheme
(format "My ~a costs $~1,2F" "pen" 19.99) ; returns "My pen costs $19.99"
</syntaxhighlight>
 
<syntaxhighlight lang="c">
<pre>
/* example in PL/I */
put string(some_string) edit('My ', 'pen', ' costs', 19.99)(a,a,a,p'$$$V.99')
/* returns "My pen costs $19.99" */
</syntaxhighlight>
</pre>
<!-- endsection -->
 
Line 1,341 ⟶ 1,342:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>''string<sub>1</sub>'' '''ne''' ''string<sub>2</sub>'', or </code><br><code>''string<sub>1</sub>'' NE ''string<sub>2</sub>''</code>
|[[ALGOL 68]] – note: the operator "'''ne'''" is literally in '''bold''' type-font.
|-
| <code>''string<sub>1</sub>'' /= ''string<sub>2</sub>''</code>
|[[ALGOL 68]], [[Ada (programming language)|Ada]], [[Erlang (programming language)|Erlang]], [[Fortran]], [[Haskell (programming language)|Haskell]]
|-
| <code>''string<sub>1</sub>'' <> ''string<sub>2</sub>''</code>
|[[BASIC]], [[Visual Basic (classic)|VB]], [[Visual Basic .NET|VB .NET]], [[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]]), [[OCaml]], [[PHP]], [[Seed7]], [[Standard ML]], [[F Sharp (programming language)|F#]], [[COBOL]], [[Cobra (programming language)|Cobra]], [[Python 2]] (deprecated)
|-
| <code>''string<sub>1</sub>'' # ''string<sub>2</sub>''</code>
Line 1,356 ⟶ 1,357:
|-
| <code>''string<sub>1</sub>'' ne ''string<sub>2</sub>''</code>
|[[Perl]], [[Raku (programming language)|Raku]]
|-
| <code>(string<> ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>
Line 1,362 ⟶ 1,363:
|-
| <code>(string/= ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>
|[[Common Lisp]]
|-
| <code>(string/= ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>
|[[ISLISP]]
|-
| <code>(not= ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>
|[[Clojure]]
|-
| <code>''string<sub>1</sub>'' != ''string<sub>2</sub>''</code>
Line 1,374 ⟶ 1,375:
|-
| <code>''string<sub>1</sub>'' !== ''string<sub>2</sub>''</code>
|[[JavaScript]], [[PHP]]
|-
| <code>''string<sub>1</sub>'' \= ''string<sub>2</sub>''</code>
|[[Rexx]]
|-
| <code>''string<sub>1</sub>'' ¬= ''string<sub>2</sub>''</code>
|[[PL/I]]
|-
| <code>test ''string<sub>1</sub>'' != ''string<sub>2</sub>'', or <br /code><br><code>[ ''string<sub>1</sub>'' != ''string<sub>2</sub>'' ]</code>
|[[Bourne Shell]]
|-
| <code>''string<sub>1</sub>'' -ne ''string<sub>2</sub>'', or <br /code><br><code>-not [string]::Equals(''string<sub>1</sub>'', ''string<sub>2</sub>'')</code>
|[[Windows PowerShell]]
|-
Line 1,444 ⟶ 1,445:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code> join(''separator'', ''list_of_strings'')</code> returns a list of strings joined with a separator
|-
Line 1,455 ⟶ 1,456:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>std.string.join(''array_of_strings'', ''separator'')</code>
Line 1,481 ⟶ 1,482:
|[[Common Lisp]]
|-
| <code>(clojure.string/join ''separator'' ''list_of_strings'')<br/code><br><code>(apply str (interpose ''separator'' ''list_of_strings''))</code>
|[[Clojure]]
|-
Line 1,497 ⟶ 1,498:
|-
| <code>Data.List.intercalate ''separator'' ''list_of_strings''</code>
|[[Haskell (programming language)|Haskell]] (GHC 6.8+)
|-
| <code>Join(''array_of_strings'', ''separator'')</code>
Line 1,508 ⟶ 1,509:
|[[Java (programming language)|Java]] 8+
|-
| <code>&{$OFS=''$separator''; "''$array_of_strings''"}, or <br /code><br><code>''array_of_strings'' -join ''separator''</code>
|[[Windows PowerShell]]
|-
Line 1,515 ⟶ 1,516:
|-
| <code>table.concat(''table_of_strings'', ''separator'')</code>
|[[Lua (programming language)|Lua]]
|-
| <code><nowiki>{|String streamContents: [ :stream |</nowiki> ''collectionOfAnything'' asStringOn: stream delimiter: ''separator'' <nowiki>]</nowiki> <br/code><br><code>''collectionOfAnything'' joinUsing: ''separator''</code>
|[[Smalltalk]] ([[Squeak]], [[Pharo]])
|-
Line 1,573 ⟶ 1,574:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>left(''string'',''n'')</code> returns string
|-
Line 1,581 ⟶ 1,582:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
|<code>{{codett|string (string'First .. string'First +|ada}} ''n'' - 1)</code>
|[[Ada (programming language)|Ada]]
|-
Line 1,604 ⟶ 1,605:
|[[Objective-C]] (<code>NSString *</code> only)
|-
| <code>{{codett|(apply str (take|clojure}} ''n'' ''string''))</code>
|[[Clojure]]
|-
Line 1,622 ⟶ 1,623:
|[[Rexx]], [[Erlang (programming language)|Erlang]]
|-
| <code>''string''[0, ''n''] <br /code><br><code> ''string''[0..''n'' - 1]</code>
|[[Ruby (programming language)|Ruby]]
|-
Line 1,635 ⟶ 1,636:
|-
| <code>leftstr(''string'', ''n'')</code>
|[[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
|-
|<code>''copy'' (''string'',1,''n'')</code>
Line 1,641 ⟶ 1,642:
|-
| <code>''string''.substring(0,''n'')</code>
|[[Java (programming language)|Java]],<ref>if n is larger than the length of the string, Java will throw an IndexOutOfBoundsException</ref> [[JavaScript]]
|-
| <code>(string-take ''string'' ''n'')</code>
Line 1,647 ⟶ 1,648:
|-
| <code>take ''n'' ''string''</code>
|[[Haskell (programming language)|Haskell]]
|-
| <code>String.extract (''string'', ''n'', NONE)</code>
Line 1,658 ⟶ 1,659:
|[[F Sharp (programming language)|F#]]
|-
| <code>string.sub(''string'', 1, ''n'') <br /code><br><code> (''string''):sub(1, ''n'')</code>
|[[Lua (programming language)|Lua]]
|-
Line 1,700 ⟶ 1,701:
; Examples in Scheme
(use-modules (srfi srfi-13))
(string-take "abcde", 3) ; returns "abc"
(string-take "abcde", 8) ; error
</syntaxhighlight>
 
<syntaxhighlight lang="cppvbscript">
' Examples in Visual Basic
Left("sandroguidi", 3) ' returns "san"
Left("sandroguidi", 100) ' returns "sandroguidi"
</syntaxhighlight>
Line 1,721 ⟶ 1,722:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>length(''string'')</code> returns an integer number
|-
Line 1,729 ⟶ 1,730:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Returns !! Languages
|-
|<code>string'Length</code>
Line 1,738 ⟶ 1,739:
| <code></code>
|[[ALGOL 68]]
|C-
|<code>echo "${#''string_param''}"</code>
| <code></code>
|[[Bash (Unix shell)|Bash]]
|-
| <code>length(''string'')</code>
| <code></code>
|[[Ingres (database)|Ingres]], [[Perl 5]] 5, [[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]]), [[Rexx]], [[Seed7]], [[SQL]], [[PL/I]]
|-
| <code>len(''string'')</code>
Line 1,759 ⟶ 1,764:
|[[Visual Basic .NET|VB .NET]], [[C Sharp (programming language)|C#]], [[Windows PowerShell]], [[F Sharp (programming language)|F#]]
|-
| <code>chars(''string'')</code> <br /> <code>''string''.chars</code>
|Number of graphemes (NFG)
|[[Raku (programming language)|Raku]]
|-
| <code>codes(''string'')</code> <br /> <code>''string''.codes</code>
|Number of Unicode code points
|[[Raku (programming language)|Raku]]
Line 1,809 ⟶ 1,814:
| <code>length ''string''</code>
|Number of Unicode code points
|[[Haskell (programming language)|Haskell]]
|-
| <code>''string''.length</code>
Line 1,827 ⟶ 1,832:
|[[Swift (programming language)|Swift]] (1.0–1.1)
|-
| <code>string.len(''string'') <br /code><br><code> (''string''):len() <br /code><br><code> #''string''</code>
| <code></code>
|[[Lua (programming language)|Lua]]
Line 1,835 ⟶ 1,840:
|[[Smalltalk]]
|-
| <code>LEN(''string''), or </code><br><code>LEN_TRIM(''string'')</code>
| <code></code>
|[[Fortran]]
Line 1,920 ⟶ 1,925:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>lowercase(''string'')</code> returns string
|-
! Description
| Returns the string in lower case.
|}
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>LCase(''string'') </code>
|[[Visual Basic (classic)|VB]]
|-
| <code>lcase(''string'') </code>
|[[FreeBASIC]]
|-
Line 1,945 ⟶ 1,950:
|[[C (programming language)|C]]<ref>operates on one character</ref>
|-
| <code>std.string.toLower(''string'') </code>
|[[D (programming language)|D]]
|-
Line 1,952 ⟶ 1,957:
|-
| <code>lowercase(''string'')</code>
|[[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
|-
| <code>strtolower(''string'')</code>
Line 1,991 ⟶ 1,996:
|-
| <code>map Char.toLower ''string''</code>
|[[Haskell (programming language)|Haskell]]
|-
| <code>''string''.toLowerCase()</code>
Line 2,005 ⟶ 2,010:
|[[Objective-C]] (<code>NSString *</code> only), [[Swift (programming language)|Swift]] (Foundation)
|-
| <code>string.lower(''string'') <br /code><br><code> (''string''):lower()</code>
|[[Lua (programming language)|Lua]]
|-
Line 2,035 ⟶ 2,040:
<syntaxhighlight lang="csharp">
// Example in C#
"Wiki means fast?".ToLower(); // "wiki means fast?"
</syntaxhighlight>
 
Line 2,052 ⟶ 2,057:
int i;
for (i = 0; i < sizeof(string) - 1; ++i) {
/* transform characters in place, one by one */
string[i] = tolower(string[i]);
}
Line 2,062 ⟶ 2,067:
<syntaxhighlight lang="perl6">
# Example in Raku
"Wiki means fast?".lc; # "wiki means fast?"
</syntaxhighlight>
 
Line 2,075 ⟶ 2,080:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <string>.partition(''separator'') returns the sub-string before the separator; the separator; then the sub-string after the separator.
|-
! Description
| Splits the given string by the separator and returns the three substrings that together make the original.
|}
{| class="wikitable sortable"
Line 2,094 ⟶ 2,099:
|-
| <code>split /(''separator'')/, ''string'', 2</code>
|[[Perl 5]] 5
|
|-
| <code>split ''separator'', ''string'', 2</code> <br /> <code>''string''.split( ''separator'', 2 )</code>
|[[Raku (programming language)|Raku]]
|Separator does not have to be a regular expression
Line 2,119 ⟶ 2,124:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>replace(''string'', ''find'', ''replace'')</code> returns string
|-
Line 2,127 ⟶ 2,132:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>changestr(''find'', ''string'', ''replace'')</code>
Line 2,163 ⟶ 2,168:
|-
| <code>''string'' =~ s/''find_regex''/''replace''/g<ref name="regex">The "find" string in this construct is interpreted as a [[regular expression]]. Certain characters have special meaning in regular expressions. If you want to find a string literally, you need to quote the special characters.</ref></code>
|[[Perl 5]] 5
|-
| <code>''string''.subst(''find'', ''replace'', :g)</code>
|[[Raku (programming language)|Raku]]
|-
| <code>''string''.replace(''find'', ''replace'', "g") <ref>third parameter is non-standard</ref> or<br /code><br><code> ''string''.replace(/''find_regex''/g, ''replace'')<ref name="regex" /></code>
|[[JavaScript]]
|-
Line 2,177 ⟶ 2,182:
|[[Bash (Unix shell)|Bash]]
|-
| <code>''string''.replace(''find'', ''replace''), or<br /code><br><code>''string'' -replace ''find_regex'', ''replace''<ref name="regex" /></code>
|[[Windows PowerShell]]
|-
Line 2,189 ⟶ 2,194:
|[[Swift (programming language)|Swift]] (Foundation)
|-
| <code>string.gsub(''string'', ''find'', ''replace'') <br /code><br><code> (''string''):gsub(''find'', ''replace'')</code>
|[[Lua (programming language)|Lua]]
|-
Line 2,245 ⟶ 2,250:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>reverse(''string'')</code>
|-
Line 2,253 ⟶ 2,258:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>reverse ''string''</code>
|[[Perl]] 5]], [[Haskell (programming language)|Haskell]]
|-
| <code>flip ''string''</code> <br /> <code>''string''.flip</code>
|[[Raku (programming language)|Raku]]<!-- reverses graphemes -->
|-
Line 2,297 ⟶ 2,302:
|[[JavaScript]]
|-
| <code>string.reverse(''string'') <br /code><br><code> (''string''):reverse()</code>
|[[Lua (programming language)|Lua]]
|-
Line 2,365 ⟶ 2,370:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>rfind(''string'',''substring'')</code> returns integer
|-
Line 2,387 ⟶ 2,392:
|-
| <code>rindex(''string'',''substring''«,''startpos''»)</code>
|[[Perl 5]] 5
|returns −1
|-
| <code>rindex(''string'',''substring''«,''startpos''»)</code> <br /> <code>''string''.rindex(''substring''«,''startpos''»)</code>
|[[Raku (programming language)|Raku]]
|returns {{mono|Nil}}
|-
| <code>strrpos(''string'',''substring''«,''startpos''»)</code>
|[[PHP]]
|returns {{mono|FALSE}}
|-
| <code>''string''.rfind(''substring''«,''startpos''»)</code>
|[[C++]] (STL)
|returns {{mono|std::string::npos}}
|-
| <code>std.string.rfind(''string'', ''substring'')</code>
Line 2,411 ⟶ 2,416:
|-
|<code>''string''.rindex(''substring''«,''startpos''«, ''endpos''»»)</code>
|raises {{mono|ValueError}}
|-
|<code>rpos(''string'', ''substring''«,''startpos''»)</code>
Line 2,419 ⟶ 2,424:
|<code>''string''.rindex(''substring''«,''startpos''»)</code>
|[[Ruby (programming language)|Ruby]]
|returns {{mono|nil}}
|-
| <code>strings.LastIndex(''string'', ''substring'')</code>
Line 2,435 ⟶ 2,440:
| <code>(search ''substring'' ''string'' :from-end t)</code>
|[[Common Lisp]]
|returns {{mono|NIL}}
|-
| <code>[''string'' rangeOfString:''substring'' options:NSBackwardsSearch].___location</code>
|[[Objective-C]] (<code>NSString *</code> only)
|returns {{mono|NSNotFound}}
|-
| <code>Str.search_backward (Str.regexp_string ''substring'') ''string'' (Str.length ''string'' - 1)</code>
|[[OCaml]]
|raises {{mono|Not_found}}
|-
| <code>string.match(''string'', '.*()'..''substring'') <br /code><br><code> ''string'':match('.*()'..''substring'')</code>
|[[Lua (programming language)|Lua]]
|returns {{mono|nil}}
|-
| <code>Ada.Strings.Unbounded.Index(Source => ''string'', Pattern => ''substring'', <br /> Going => Ada.Strings.Backward)</code>
|[[Ada (programming language)|Ada]]
|returns 0
Line 2,471 ⟶ 2,476:
| <code>''string''.rfind(''substring'')</code>
| [[Rust (programming language)|Rust]]<ref>See the [https://doc.rust-lang.org/stable/std/primitive.str.html#method.rfind <code>str::rfind</code>] method.</ref>
| returns [[Option type|<code>{{mono|None</code>}}]]
|}
 
Line 2,513 ⟶ 2,518:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>right(''string'',''n'')</code> returns string
|-
Line 2,521 ⟶ 2,526:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
|<code>string (string'Last - ''n'' + 1 .. string'Last)</code>
Line 2,548 ⟶ 2,553:
|-
| <code>''string''.slice(-''n'')</code>
|[[JavaScript]]<ref>{{cite web |url=https://es5.github.com/#x15.5.4.13 |title=Annotated ES5 |publisher=Es5.github.com |access-date=2013-08-18 |archive-date=2013-01-28 |archive-url=https://web.archive.org/web/20130128185825/https://es5.github.com/#x15.5.4.13 |url-status=dead }}</ref>
|-
| <code>right(''string'',''n'' «,''padchar''»)</code>
Line 2,554 ⟶ 2,559:
|-
| <code>substr(''string'',-''n'')</code>
|[[Perl 5]] 5, [[PHP]]
|-
| <code>substr(''string'',*-''n'')</code> <br /> <code>''string''.substr(*-''n'')</code>
|[[Raku (programming language)|Raku]]
|-
Line 2,580 ⟶ 2,585:
|[[OCaml]]<ref name="ReferenceA"/>
|-
| <code>string.sub(''string'', -''n'') <br /code><br><code> (''string''):sub(-''n'')</code>
|[[Lua (programming language)|Lua]]
|-
Line 2,621 ⟶ 2,626:
; Examples in Scheme
(use-modules (srfi srfi-13))
(string-take-right "abcde", 3) ; returns "cde"
(string-take-right "abcde", 8) ; error
</syntaxhighlight>
Line 2,627 ⟶ 2,632:
<syntaxhighlight lang="vbnet">
' Examples in Visual Basic
Right("sandroguidi", 3) ' returns "idi"
Right("sandroguidi", 100) ' returns "sandroguidi"
</syntaxhighlight>
 
Line 2,636 ⟶ 2,641:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <string>.rpartition(''separator'') Searches for the separator from right-to-left within the string then returns the sub-string before the separator; the separator; then the sub-string after the separator.
|-
! Description
| Splits the given string by the right-most separator and returns the three substrings that together make the original.
|}
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>''string''.rpartition(''separator'')</code>
Line 2,665 ⟶ 2,670:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <string>.split(''separator''[, ''limit'']) splits a string on separator, optionally only up to a limited number of substrings
|-
Line 2,673 ⟶ 2,678:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>split(/''separator''/, ''string''«, ''limit''»)</code>
|[[Perl 5]] 5
|-
| <code>split(''separator'', ''string''«, ''limit''»)</code> <br /> <code>''string''.split(''separator'', «''limit''»)</code>
|[[Raku (programming language)|Raku]]
|-
Line 2,693 ⟶ 2,698:
|[[Erlang (programming language)|Erlang]]
|-
| <code>strings.Split(''string'', ''separator'')<br /code><br><code>strings.SplitN(''string'', ''separator'', ''limit'')</code>
|[[Go (programming language)|Go]]
|-
Line 2,732 ⟶ 2,737:
|[[Tcl]]
|-
| <code>(''separator''≠''string'')⊂''string''</code> orin APL2<br><code>''separator''(≠⊆⊢)''string''</code> in APL2 and Dyalog APL 16.0 respectively
|[[APL (programming language)|APL]]
|-
Line 2,804 ⟶ 2,809:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>substring(''string'', ''startpos'', ''endpos'')</code> returns string <br /> <code>substr(''string'', ''startpos'', ''numChars'')</code> returns string
|-
! Description
| Returns a substring of ''string'' between starting at ''startpos'' and ''endpos'', or starting at ''startpos'' of length ''numChars''. The resulting string is truncated if there are fewer than ''numChars'' characters beyond the starting point. ''endpos'' represents the index after the last character in the substring. Note that for variable-length encodings such as [[UTF-8]], [[UTF-16]] or [[Shift-JIS]], it can be necessary to remove string positions at the end, in order to avoid invalid strings.
Line 2,812 ⟶ 2,817:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
|<code>string[''startpos'':''endpos'']</code>
Line 2,833 ⟶ 2,838:
|-
| <code>substr(''string'', ''startpos'', ''numChars'')</code>
|[[AWK]] (changes string), [[Perl 5]] 5,<ref name="substr2"/><ref name="substr4"/> [[PHP]]<ref name="substr2"/><ref name="substr4"/>
|-
| <code>substr(''string'', ''startpos'', ''numChars'')</code> <br /> <code>''string''.substr(''startpos'', ''numChars'')</code>
|[[Raku (programming language)|Raku]]<ref name="substr5"/><ref name="substr6"/>
|-
Line 2,847 ⟶ 2,852:
|[[Pick Basic]]
|-
| <code>''string''[''startpos'', ''numChars''] <br /code><br><code> ''string''[''startpos'' .. ''endpos''-1] <br /code><br><code> ''string''[''startpos'' ... ''endpos'']</code>
|[[Ruby (programming language)|Ruby]]<ref name="substr2"/><ref name="substr3"/>
|-
| <code>''string''[''startpos'' .. ''endpos''] <br /code><br><code> ''string''[''startpos'' len ''numChars'']</code>
|[[Seed7]]
|-
Line 2,866 ⟶ 2,871:
|-
| <code>copy(''string'', ''startpos'', ''numChars'')</code>
|[[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
|-
| <code>(substring ''string'' ''startpos'' ''endpos'')</code>
Line 2,883 ⟶ 2,888:
|[[Standard ML]]
|-
| <code>string:sub_string(''string'', ''startpos'', ''endpos'')<br /code><br><code>string:substr(''string'', ''startpos'', ''numChars'')</code>
|[[Erlang (programming language)|Erlang]]
|-
Line 2,893 ⟶ 2,898:
|-
| <code>take ''numChars'' $ drop ''startpos'' ''string''</code>
|[[Haskell (programming language)|Haskell]]
|-
| <code>[''string'' substringWithRange:NSMakeRange(''startpos'', ''numChars'')]</code>
Line 2,901 ⟶ 2,906:
|[[F Sharp (programming language)|F#]]
|-
| <code>string.sub(''string'', ''startpos'', ''endpos'') <br /code><br><code> (''string''):sub(''startpos'', ''endpos'')</code>
|[[Lua (programming language)|Lua]]<ref name="substr2"/><ref name="substr3"/>
|-
Line 2,980 ⟶ 2,985:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>uppercase(''string'')</code> returns string
|-
! Description
| Returns the string in upper case.
|}
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>UCase(''string'') </code>
|[[Visual Basic (classic)|VB]]
|-
| <code>ucase(''string'') </code>
|[[FreeBASIC]]
|-
| <code>toupper(''string'') </code>
|[[AWK]] (changes string)
|-
Line 3,008 ⟶ 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,018 ⟶ 3,023:
|-
| <code>uppercase(''string'')</code>
|[[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]])
|-
|<code>upcase(''char'')</code>
|[[Object Pascal]] ([[Delphi (programming languagesoftware)|Delphi]]) (operates on one character)
|-
| <code>strtoupper(''string'')</code>
Line 3,032 ⟶ 3,037:
|[[Bash (Unix shell)|Bash]]
|-
|<code>[[echo (command)|echo]] "string" <nowiki>|</nowiki> [[tr (program)|tr]] 'a-z' 'A-Z' </code>
|[[Unix]]
|-
| <code>translate(''string'')</code>,<br><code>UPPER orvariables</code><br><code>PARSE UPPER VAR SrcVar DstVar</code>
<code>UPPER variables</code>, or<br/>
<code>PARSE UPPER VAR SrcVar DstVar</code>
|[[Rexx]]
|-
Line 3,062 ⟶ 3,065:
|-
| <code>map Char.toUpper ''string''</code>
|[[Haskell (programming language)|Haskell]]
|-
| <code>''string''.toUpperCase()</code>
|[[Java (programming language)|Java]], [[JavaScript]]
|C-
| <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,076 ⟶ 3,082:
|[[Objective-C]] (<code>NSString *</code> only), [[Swift (programming language)|Swift]] (Foundation)
|-
| <code>string.upper(''string'') <br /code><br><code> (''string''):upper()</code>
|[[Lua (programming language)|Lua]]
|-
Line 3,098 ⟶ 3,104:
|-
| <code>''string''.to_uppercase()</code>
| [[Rust (programming language)|Rust]]<ref>In Rust, the [https://doc.rust-lang.org/stable/std/primitive.str.html#method.to_uppercase <code>str::to_uppercase</code>] method returns a newly allocated [https://doc.rust-lang.org/stable/std/string/struct.String.html <code>String</code>] with any lowercase characters changed to uppercase ones following the Unicode rules.</ref>
|}
 
<syntaxhighlight lang="csharp">
// Example in C#
"Wiki means fast?".ToUpper(); // "WIKI MEANS FAST?"
</syntaxhighlight>
 
<syntaxhighlight lang="perl">
# Example in Perl 5
uc("Wiki means fast?"); # "WIKI MEANS FAST?"
</syntaxhighlight>
 
Line 3,114 ⟶ 3,120:
# Example in Raku
uc("Wiki means fast?"); # "WIKI MEANS FAST?"
"Wiki means fast?".uc; # "WIKI MEANS FAST?"
</syntaxhighlight>
 
Line 3,138 ⟶ 3,144:
<syntaxhighlight lang="vbnet">
' Example in Visual Basic
UCase("Wiki means fast?") ' "WIKI MEANS FAST?"
</syntaxhighlight>
<!-- endsection -->
Line 3,148 ⟶ 3,154:
{| class="wikitable"
|- style="text-align:left;"
! Example usage !! Languages
|-
| <code>''String''.Trim([''chars''])</code>
Line 3,162 ⟶ 3,168:
|[[Factor (programming language)|Factor]]
|-
| <code>{{codett|(string-trim '(#\Space #\Tab #\Newline)|lisp}} ''string'')</code>
|[[Common Lisp]]
|-
| <code>(string-trim ''string'')</code>
|[[Scheme (programming language)|Scheme]]
|-
| <code>''string''.trim()</code>
Line 3,172 ⟶ 3,178:
|-
| <code>Trim(''String'')</code>
|[[Pascal (programming language)|Pascal]],<ref>{{cite web|url=http://gnu-pascal.de/gpc-hr/Trim.html |title=Trim – GNU Pascal priručnik |publisher=Gnu-pascal.de |access-date=2013-08-24}}</ref> [[QBasic]], [[Visual Basic (classic)|Visual Basic]], [[Delphi (programming languagesoftware)|Delphi]]
|-
| <code>''string''.strip()</code>
Line 3,189 ⟶ 3,195:
|[[Erlang (programming language)|Erlang]]
|-
| <code>''string''.strip or </code><br><code>''string''.lstrip or </code><br><code>''string''.rstrip</code>
|[[Ruby (programming language)|Ruby]]
|-
Line 3,198 ⟶ 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>
|[[Tcl]]
|-
| <code>TRIM(''string'') or </code><br><code>TRIM(ADJUSTL(''string''))</code>
|[[Fortran]]
|-
Line 3,216 ⟶ 3,222:
|[[SQL]]
|-
| <code>TRIM(''string'') or </code><br><code>LTrim(''string'') or </code><br><code>RTrim(''String'')</code>
|[[ColdFusion]]
|-
Line 3,301 ⟶ 3,307:
</syntaxhighlight>
 
Note that withWith boost's function named simply <code>trim</code> the input sequence is modified in-place, and does not returnreturns ano result.
 
Another [[open-source software|open source]] C++ library [[Qt (toolkitsoftware)|Qt]], has several trim variants, including a standard one:<ref>[http://doc.trolltech.com/4.5/qstring.html#trimmed] {{webarchive |url=https://web.archive.org/web/20090802041055/http://doc.trolltech.com/4.5/qstring.html#trimmed |date=August 2, 2009 }}</ref>
 
<syntaxhighlight lang="cpp">
Line 3,313 ⟶ 3,319:
 
====Haskell====
A trim algorithm in [[Haskell (programming language)|Haskell]]:
 
<syntaxhighlight lang="haskell">
Line 3,359 ⟶ 3,365:
Also available for Perl is '''StripLTSpace''' in <code>String::Strip</code> from [[CPAN]].
 
There are, however, two functions that are commonly used to strip whitespace from the end of strings, <code>chomp</code> and <code>chop</code>:
* <code>[http://perldoc.perl.org/functions/chop.html chop]</code> removes the last character from a string and returns it.
* <code>[http://perldoc.perl.org/functions/chomp.html chomp]</code> removes the trailing newline character(s) from a string if present. (What constitutes a newline is [http://perldoc.perl.org/perlvar.html $INPUT_RECORD_SEPARATOR] dependent).