Content deleted Content added
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5 |
m →left: {{codett}} |
||
(13 intermediate revisions by 7 users not shown) | |||
Line 1:
{{Short description|none}}
{{Redirect|String functions|string functions in formal language theory|String operations}}
{{Further|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.
Line 29 ⟶ 30:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>charAt(string,integer)</code> returns character.
|-
Line 118 ⟶ 119:
|0
|-
| <code>substr(''string'', ''i'', 1)</code><br
|[[Raku (programming language)|Raku]]<ref name="at2"/>
|0
Line 138 ⟶ 139:
|0
|-
| <code>string.sub(''string'', ''i'', ''i'')<
|[[Lua (programming language)|Lua]]<ref name="at1"/>
|1
Line 173 ⟶ 174:
<syntaxhighlight lang="pascal">
{ Example in Pascal }
var
MyStr: string = 'Hello, World';
MyChar: Char;
Line 253 ⟶ 254:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>compare(string<sub>1</sub>,string<sub>2</sub>)</code> returns integer.
|-
Line 261 ⟶ 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 332 ⟶ 333:
|[[Objective-C]] (<code>NSString *</code> only)
|-
| <code>LLT(''string<sub>1</sub>'',''string<sub>2</sub>'')<
|[[Fortran]]<ref>returns <code>.TRUE.</code> or <code>.FALSE.</code>. These functions are based on the ASCII collating sequence.</ref>
|-
Line 341 ⟶ 342:
|[[Go (programming language)|Go]]
|-
| <code>string compare
|[[Tcl]]
|-
Line 369 ⟶ 370:
<syntaxhighlight lang="rexx">
/** Example in Rexx */
compare("hello", "world") /* returns index of mismatch: 1 */
</syntaxhighlight>
Line 384 ⟶ 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 392 ⟶ 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
|[[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
|[[ALGOL 68]]
|-
| <code>(stringOP? ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>, where <code>OP</code> can be any of
|[[Scheme (programming language)|Scheme]]
|-
| <code>(stringOP ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>, where <code>OP</code> can be any of
|[[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
|[[Common Lisp]]
|-
| <code>(stringOP ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>, where <code>OP</code> can be any of
|[[ISLISP]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[Rexx]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[PL/I]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[Ada (programming language)|Ada]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[Erlang (programming language)|Erlang]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[Haskell]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[Perl]], [[Raku (programming language)|Raku]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[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>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[Windows PowerShell]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[Lua (programming language)|Lua]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[Smalltalk]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of
|[[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
| [[COBOL]]
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code> where <code>OP</code> can be any of
| [[Cobra (programming language)|Cobra]]
|-
Line 486 ⟶ 487:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>concatenate(string<sub>1</sub>,string<sub>2</sub>)</code> returns string.
|-
Line 495 ⟶ 496:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>''string<sub>1</sub>'' & ''string<sub>2</sub>''</code>
Line 600 ⟶ 601:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>contains(''string'',''substring'')</code> returns boolean
|-
Line 726 ⟶ 727:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>''string<sub>1</sub>'' == ''string<sub>2</sub>''</code>
Line 734 ⟶ 735:
|[[JavaScript]], [[PHP]]
|-
| <code>''string<sub>1</sub>'' == ''string<sub>2</sub>''
|[[Fortran]]
|-
Line 749 ⟶ 750:
|[[ALGOL 68]], [[Ada (programming language)|Ada]], [[Object Pascal]] ([[Delphi (software)|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>''
|[[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 761 ⟶ 762:
|[[C Sharp (programming language)|C#]]
|-
| <code>''string<sub>1</sub>'' -eq ''string<sub>2</sub>''
|[[Windows PowerShell]]
|-
| <code>[''string<sub>1</sub>'' isEqualToString:''string<sub>2</sub>'']
|[[Objective-C]] (<code>NSString *</code> only)
|-
Line 812 ⟶ 813:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>find(''string'',''substring'')</code> returns integer
|-
Line 845 ⟶ 846:
|returns −1
|-
| <code>index(''string'',''substring''«,''startpos''»)</code><br
|[[Raku (programming language)|Raku]]
|returns Nil
Line 940 ⟶ 941:
|returns NSNotFound
|-
| <code>string.find(''string'', ''substring'')<
|[[Lua (programming language)|Lua]]
|returns nil
|-
| <code>''string'' indexOfSubCollection: ''substring'' startingAt: ''startpos'' ifAbsent: ''aBlock''<
|[[Smalltalk]] ([[Squeak]], [[Pharo]])
|evaluate aBlock which is a block closure (or any object understanding value)<br
|-
| <code>startpos = INDEX(''string'', ''substring'' «,''back''» «, ''kind''»)</code>
Line 1,006 ⟶ 1,007:
* Visual Basic
*: <syntaxhighlight lang="vbnet">
' Examples in
InStr("Hello mate", "e") ' returns 2
InStr(5, "Hello mate", "e") ' returns 10
Line 1,019 ⟶ 1,020:
</syntaxhighlight>
*: <syntaxhighlight lang="smalltalk">
I'Hello mate'
indexOfSubCollection:'late'
ifAbsent:[ 99 ] "returns 99"
</syntaxhighlight>
*: <syntaxhighlight lang="smalltalk">
'Hello mate'
indexOfSubCollection:'late'
ifAbsent:[ self error ] "raises an exception"
Line 1,035 ⟶ 1,036:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>find_character(''string'',''char'')</code> returns integer
|-
Line 1,100 ⟶ 1,101:
|raises {{mono|Not_found}}
|-
| <code>position = SCAN (''string'', ''set'' «, ''back''» «, ''kind''»)
|[[Fortran]]
|returns zero
|-
| <code>''string'' indexOf: ''char'' ifAbsent: aBlock<
|[[Smalltalk]]
|evaluate <code>aBlock</code> which is a <code>BlockClosure</code> (or any object understanding value)<br
|-
| <code>index(''string'', ''char'', ''startpos'' )</code>
Line 1,152 ⟶ 1,153:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>format(''formatstring'', ''items'')</code> returns string
|-
Line 1,160 ⟶ 1,161:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format
! Languages
! Format string syntax
Line 1,263 ⟶ 1,264:
|[[C (programming language)|C]]
|-
| <code>string.format(''formatstring'', ''items'')<
|[[Lua (programming language)|Lua]]
|[[C (programming language)|C]]
Line 1,283 ⟶ 1,284:
|[[C (programming language)|C]]
|-
| <code>''formatnumbers'' ⍕ ''items''</code>
|[[APL (programming language)|APL]]
|APL
Line 1,321 ⟶ 1,322:
#Example in Python 3.6+
pen = "pen"
f"My {pen} costs {19.99}" #returns "My pen costs 19.99"
</syntaxhighlight>
Line 1,341 ⟶ 1,342:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>''string<sub>1</sub>'' '''ne''' ''string<sub>2</sub>''
|[[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]]
|-
| <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>''
|[[Bourne Shell]]
|-
| <code>''string<sub>1</sub>'' -ne ''string<sub>2</sub>''
|[[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'')<
|[[Clojure]]
|-
Line 1,508 ⟶ 1,509:
|[[Java (programming language)|Java]] 8+
|-
| <code>&{$OFS=''$separator''; "''$array_of_strings''"}
|[[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><
|[[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'']<
|[[Ruby (programming language)|Ruby]]
|-
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,658 ⟶ 1,659:
|[[F Sharp (programming language)|F#]]
|-
| <code>string.sub(''string'', 1, ''n'')<
|[[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>
Line 1,706 ⟶ 1,707:
<syntaxhighlight lang="vbscript">
' 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,763 ⟶ 1,764:
|[[Visual Basic .NET|VB .NET]], [[C Sharp (programming language)|C#]], [[Windows PowerShell]], [[F Sharp (programming language)|F#]]
|-
| <code>chars(''string'')</code><br
|Number of graphemes (NFG)
|[[Raku (programming language)|Raku]]
|-
| <code>codes(''string'')</code><br
|Number of Unicode code points
|[[Raku (programming language)|Raku]]
Line 1,831 ⟶ 1,832:
|[[Swift (programming language)|Swift]] (1.0–1.1)
|-
| <code>string.len(''string'')<
| <code></code>
|[[Lua (programming language)|Lua]]
Line 1,839 ⟶ 1,840:
|[[Smalltalk]]
|-
| <code>LEN(''string'')
| <code></code>
|[[Fortran]]
Line 1,924 ⟶ 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'')
|[[Visual Basic (classic)|VB]]
|-
| <code>lcase(''string'')
|[[FreeBASIC]]
|-
Line 1,949 ⟶ 1,950:
|[[C (programming language)|C]]<ref>operates on one character</ref>
|-
| <code>std.string.toLower(''string'')
|[[D (programming language)|D]]
|-
Line 2,009 ⟶ 2,010:
|[[Objective-C]] (<code>NSString *</code> only), [[Swift (programming language)|Swift]] (Foundation)
|-
| <code>string.lower(''string'')<
|[[Lua (programming language)|Lua]]
|-
Line 2,039 ⟶ 2,040:
<syntaxhighlight lang="csharp">
// Example in C#
"Wiki means fast?".ToLower(); // "wiki means fast?"
</syntaxhighlight>
Line 2,056 ⟶ 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,066 ⟶ 2,067:
<syntaxhighlight lang="perl6">
# Example in Raku
"Wiki means fast?".lc; # "wiki means fast?"
</syntaxhighlight>
Line 2,079 ⟶ 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,101 ⟶ 2,102:
|
|-
| <code>split ''separator'', ''string'', 2</code><br
|[[Raku (programming language)|Raku]]
|Separator does not have to be a regular expression
Line 2,123 ⟶ 2,124:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>replace(''string'', ''find'', ''replace'')</code> returns string
|-
Line 2,131 ⟶ 2,132:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>changestr(''find'', ''string'', ''replace'')</code>
Line 2,172 ⟶ 2,173:
|[[Raku (programming language)|Raku]]
|-
| <code>''string''.replace(''find'', ''replace'', "g") <ref>third parameter is non-standard</ref>
|[[JavaScript]]
|-
Line 2,181 ⟶ 2,182:
|[[Bash (Unix shell)|Bash]]
|-
| <code>''string''.replace(''find'', ''replace'')
|[[Windows PowerShell]]
|-
Line 2,193 ⟶ 2,194:
|[[Swift (programming language)|Swift]] (Foundation)
|-
| <code>string.gsub(''string'', ''find'', ''replace'')<
|[[Lua (programming language)|Lua]]
|-
Line 2,249 ⟶ 2,250:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>reverse(''string'')</code>
|-
Line 2,257 ⟶ 2,258:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>reverse ''string''</code>
|[[Perl]] 5, [[Haskell]]
|-
| <code>flip ''string''</code><br
|[[Raku (programming language)|Raku]]<!-- reverses graphemes -->
|-
Line 2,301 ⟶ 2,302:
|[[JavaScript]]
|-
| <code>string.reverse(''string'')<
|[[Lua (programming language)|Lua]]
|-
Line 2,369 ⟶ 2,370:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>rfind(''string'',''substring'')</code> returns integer
|-
Line 2,394 ⟶ 2,395:
|returns −1
|-
| <code>rindex(''string'',''substring''«,''startpos''»)</code><br
|[[Raku (programming language)|Raku]]
|returns {{mono|Nil}}
Line 2,449 ⟶ 2,450:
|raises {{mono|Not_found}}
|-
| <code>string.match(''string'', '.*()'..''substring'')<
|[[Lua (programming language)|Lua]]
|returns {{mono|nil}}
|-
| <code>Ada.Strings.Unbounded.Index(Source => ''string'', Pattern => ''substring'',
|[[Ada (programming language)|Ada]]
|returns 0
Line 2,517 ⟶ 2,518:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>right(''string'',''n'')</code> returns string
|-
Line 2,525 ⟶ 2,526:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
|<code>string (string'Last - ''n'' + 1 .. string'Last)</code>
Line 2,560 ⟶ 2,561:
|[[Perl]] 5, [[PHP]]
|-
| <code>substr(''string'',*-''n'')</code><br
|[[Raku (programming language)|Raku]]
|-
Line 2,584 ⟶ 2,585:
|[[OCaml]]<ref name="ReferenceA"/>
|-
| <code>string.sub(''string'', -''n'')<
|[[Lua (programming language)|Lua]]
|-
Line 2,625 ⟶ 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,631 ⟶ 2,632:
<syntaxhighlight lang="vbnet">
' Examples in Visual Basic
Right("sandroguidi", 3) ' returns "idi"
Right("sandroguidi", 100) ' returns "sandroguidi"
</syntaxhighlight>
Line 2,640 ⟶ 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,669 ⟶ 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,677 ⟶ 2,678:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
| <code>split(/''separator''/, ''string''«, ''limit''»)</code>
|[[Perl]] 5
|-
| <code>split(''separator'', ''string''«, ''limit''»)</code><br
|[[Raku (programming language)|Raku]]
|-
Line 2,697 ⟶ 2,698:
|[[Erlang (programming language)|Erlang]]
|-
| <code>strings.Split(''string'', ''separator'')<
|[[Go (programming language)|Go]]
|-
Line 2,736 ⟶ 2,737:
|[[Tcl]]
|-
| <code>(''separator''≠''string'')⊂''string''</code>
|[[APL (programming language)|APL]]
|-
Line 2,808 ⟶ 2,809:
{| class="wikitable"
|- style="background:#fffeed;"
! Definition
| <code>substring(''string'', ''startpos'', ''endpos'')</code> returns string<br
|-
! 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,816 ⟶ 2,817:
{| class="wikitable sortable"
|- style="text-align:left;"
! Format !! Languages
|-
|<code>string[''startpos'':''endpos'']</code>
Line 2,839 ⟶ 2,840:
|[[AWK]] (changes string), [[Perl]] 5,<ref name="substr2"/><ref name="substr4"/> [[PHP]]<ref name="substr2"/><ref name="substr4"/>
|-
| <code>substr(''string'', ''startpos'', ''numChars'')</code><br
|[[Raku (programming language)|Raku]]<ref name="substr5"/><ref name="substr6"/>
|-
Line 2,851 ⟶ 2,852:
|[[Pick Basic]]
|-
| <code>''string''[''startpos'', ''numChars'']<
|[[Ruby (programming language)|Ruby]]<ref name="substr2"/><ref name="substr3"/>
|-
| <code>''string''[''startpos'' .. ''endpos'']<
|[[Seed7]]
|-
Line 2,887 ⟶ 2,888:
|[[Standard ML]]
|-
| <code>string:sub_string(''string'', ''startpos'', ''endpos'')<
|[[Erlang (programming language)|Erlang]]
|-
Line 2,905 ⟶ 2,906:
|[[F Sharp (programming language)|F#]]
|-
| <code>string.sub(''string'', ''startpos'', ''endpos'')<
|[[Lua (programming language)|Lua]]<ref name="substr2"/><ref name="substr3"/>
|-
Line 2,984 ⟶ 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'')
|[[Visual Basic (classic)|VB]]
|-
| <code>ucase(''string'')
|[[FreeBASIC]]
|-
| <code>toupper(''string'')
|[[AWK]] (changes string)
|-
Line 3,012 ⟶ 3,013:
|[[C (programming language)|C]] (operates on one character)
|-
|<code>{{codett|2=c|1=for(size_t i = 0, len = strlen(}}''string''); i< len; i++) ''string''[i] = toupper(''string''[i]);</code><br
|[[C (programming language)|C]] (string / char array)
|-
Line 3,036 ⟶ 3,037:
|[[Bash (Unix shell)|Bash]]
|-
|<code>[[echo (command)|echo]] "string" <nowiki>|</nowiki> [[tr (program)|tr]] 'a-z' 'A-Z'
|[[Unix]]
|-
| <code>translate(''string'')</code>
|[[Rexx]]
|-
Line 3,070 ⟶ 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,080 ⟶ 3,082:
|[[Objective-C]] (<code>NSString *</code> only), [[Swift (programming language)|Swift]] (Foundation)
|-
| <code>string.upper(''string'')<
|[[Lua (programming language)|Lua]]
|-
Line 3,102 ⟶ 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,118 ⟶ 3,120:
# Example in Raku
uc("Wiki means fast?"); # "WIKI MEANS FAST?"
"Wiki means fast?".uc; # "WIKI MEANS FAST?"
</syntaxhighlight>
Line 3,142 ⟶ 3,144:
<syntaxhighlight lang="vbnet">
' Example in Visual Basic
UCase("Wiki means fast?") ' "WIKI MEANS FAST?"
</syntaxhighlight>
<!-- endsection -->
Line 3,152 ⟶ 3,154:
{| class="wikitable"
|- style="text-align:left;"
! Example usage !! Languages
|-
| <code>''String''.Trim([''chars''])</code>
Line 3,166 ⟶ 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,193 ⟶ 3,195:
|[[Erlang (programming language)|Erlang]]
|-
| <code>''string''.strip
|[[Ruby (programming language)|Ruby]]
|-
Line 3,202 ⟶ 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
|-
|<code>string trim ''$string''</code>
|[[Tcl]]
|-
| <code>TRIM(''string'')
|[[Fortran]]
|-
Line 3,220 ⟶ 3,222:
|[[SQL]]
|-
| <code>TRIM(''string'')
|[[ColdFusion]]
|-
Line 3,363 ⟶ 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).
|