
String functions are used in computer programming languages to manipulate a string or query information about a string (some do both).
Most programming languages that have a string datatype will have some string functions although there may be other low-level ways within each language to handle strings directly. In object-oriented languages, string functions are often implemented as properties and methods of string objects. In functional and list-based languages a string is represented as a list (of character codes), therefore all list-manipulation procedures could be considered string functions. However such languages may implement a subset of explicit string-specific functions as well.
For function that manipulate strings, modern object-oriented languages, like C# and Java have immutable strings and return a copy (in newly allocated dynamic memory), while others, like C manipulate the original string unless the programmer copies data to a new string. See for example Concatenation below.
The most basic example of a string function is the length(string) function. This function returns the length of a string literal.
e.g. length("hello world") would return 11.
Other languages may have string functions with similar or exactly the same syntax or parameters or outcomes. For example, in many languages the length function is usually represented as len(string). The below list of common functions aims to help limit this confusion.
String functions common to many languages are listed below, including the different names used. The below list of common functions aims to help programmers find the equivalent function in a language. String concatenation and regular expressions are handled in separate pages. Statements in guillemets (« ⦠») are optional.
| Definition | charAt(string,integer) returns character. | |
|---|---|---|
| Description | Returns character at index in the string. | |
| Equivalent | See substring of length 1 character. |
| Format | Languages | Base index | |
|---|---|---|---|
''string''[''i''] | ALGOL 68, APL, Julia, Pascal, Object Pascal (Delphi), Seed7 | 1 | |
''string''[''i''] | C, C++, C#, Cobra, D, FreeBASIC, Go, Python, PHP, Ruby, Windows PowerShell, JavaScript, APL | 0 | |
''string''{''i''} | PHP (deprecated in 5.3) | 0 | |
''string''(''i'') | Ada | ā„1 | |
Mid(''string'',i,1) | VB | 1 | |
MID$(''string'',i,1) | BASIC | 1 | |
''string''.Chars(''i'') | VB.NET | 0 | |
''string''(''i'':''i'') | Fortran | 1 | |
''string''.charAt(''i'') | Java, JavaScript | 0 | |
''string''.[''i''] | OCaml, F# | 0 | |
''string''.chars.nth(''i'') | Rust[1] | 0 | |
''string''[''i'',''1''] | Pick Basic | 1 | |
String.sub (''string'', ''i'') | Standard ML | 0 | |
''string'' ! | i | Haskell | 0 |
(string-ref ''string'' ''i'') | Scheme | 0 | |
(char ''string'' ''i'') | Common Lisp | 0 | |
(elt ''string'' ''i'') | ISLISP | 0 | |
(get ''string'' ''i'') | Clojure | 0 | |
substr(''string'', ''i'', 1) | Perl 5 | 0 | |
substr(''string'', ''i'', 1)string.substr(''i'', 1) | Raku | 0 | |
substr(''string'', ''i'', 1) | PL/I | 1 | |
substr(''string'', ''i'', 1) | REXX | 1 | |
''string''.at(''i'') | C++ (STL) (w/ bounds checking) | 0 | |
lists:nth(''i'', ''string'') | Erlang | 1 | |
[''string'' characterAtIndex:''i''] | Objective-C (NSString * only) | 0 | |
string.sub(''string'', ''i'', ''i'')(''string''):sub(''i'', ''i'') | Lua | 1 | |
''string'' at: ''i'' | Smalltalk (w/ bounds checking) | 1 | |
string index ''string i'' | Tcl | 0 | |
StringTake[''string'', {''i''}] | Mathematica, Wolfram Language | 1 | |
''string''@''i'' | Eiffel | 1 | |
''string'' (''i'':1) | COBOL | 1 | |
${''string_param'':''i'':1} | Bash | 0 | |
''i''ā·''string'' | APL | 0 or 1 |
# Example in ALGOL 68 # "Hello, World"[2]; // 'e'
char myStr1[] = "Hello, World";printf("%c", *(myStr1 + 1)); // 'e'printf("%c", *(myStr1 + 7)); // 'W'printf("%c", myStr1[11]); // 'd'printf("%s", myStr1); // 'Hello, World'printf("%s", "Hello(2), World(2)"); // 'Hello(2), World(2)'
using std::string;
char myStr1[] = "Hello(1), World(1)";string myStr2 = "Hello(2), World(2)";std::println("Hello(3), World(3)"); // 'Hello(3), World(3)'std::println("", myStr2[6]); // '2'std::println("", myStr1.substr(5, 3)); // '(1)'
substr("Hello, World", 1, 1); # 'e'
"Hello, World"[2] # 'l'"Hello, World"[-3] # 'r'
"Hello, World".substr(1, 1); # 'e'
See also: Three-way comparison.
| Definition | compare(string<sub>1</sub>,string<sub>2</sub>) returns integer. | |
|---|---|---|
| Description | Compares two strings to each other. If they are equivalent, a zero is returned. Otherwise, most of these routines will return a positive or negative result corresponding to whether string1 is lexicographically greater than, or less than, respectively, than string2. The exceptions are the Scheme and Rexx routines which return the index of the first mismatch, and Smalltalk which answer a comparison code telling how the receiver sorts relative to string parameter. |
| Format | Languages | |
|---|---|---|
IF ''string<sub>1</sub>''<''string<sub>2</sub>'' THEN -1 ELSE ABS (''string<sub>1</sub>''>''string<sub>2</sub>'') FI | ALGOL 68 | |
cmp(''string<sub>1</sub>'', ''string<sub>2</sub>'') | Python 2 | |
(''string<sub>1</sub>'' > ''string<sub>2</sub>'') - (''string<sub>1</sub>'' < ''string<sub>2</sub>'') | Python | |
[[strcmp]](''string<sub>1</sub>'', ''string<sub>2</sub>'') | C, PHP | |
std.string.cmp(''string<sub>1</sub>'', ''string<sub>2</sub>'') | D | |
StrComp(''string<sub>1</sub>'', ''string<sub>2</sub>'') | VB, Object Pascal (Delphi) | |
''string<sub>1</sub>'' cmp ''string<sub>2</sub>'' | Perl, Raku | |
''string<sub>1</sub>'' compare: ''string<sub>2</sub>'' | Smalltalk (Squeak, Pharo) | |
''string<sub>1</sub>'' <=> ''string<sub>2</sub>'' | Ruby, C++ (STL, C++20)[2] | |
''string<sub>1</sub>''.compare(''string<sub>2</sub>'') | C++ (STL), Swift (Foundation) | |
compare(''string<sub>1</sub>'', ''string<sub>2</sub>'') | Rexx, Seed7 | |
compare(''string<sub>1</sub>'', ''string<sub>2</sub>'', ''pad'') | Rexx | |
CompareStr(''string<sub>1</sub>'', ''string<sub>2</sub>'') | Pascal, Object Pascal (Delphi) | |
''string<sub>1</sub>''.compareTo(''string<sub>2</sub>'') | Cobra, Java | |
''string<sub>1</sub>''.CompareTo(''string<sub>2</sub>'') | VB .NET, C#, F# | |
(compare ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Clojure | |
(string= ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Common Lisp | |
(string-compare ''string<sub>1</sub>'' ''string<sub>2</sub>'' ''p<'' ''p='' ''p>'') | Scheme (SRFI 13) | |
(string= ''string<sub>1</sub>'' ''string<sub>2</sub>'') | ISLISP | |
compare ''string<sub>1</sub>'' ''string<sub>2</sub>'' | OCaml | |
String.compare (''string<sub>1</sub>'', ''string<sub>2</sub>'') | Standard ML[3] | |
compare ''string<sub>1</sub>'' ''string<sub>2</sub>'' | Haskell[4] | |
[string]::Compare(''string<sub>1</sub>'', ''string<sub>2</sub>'') | Windows PowerShell | |
[''string<sub>1</sub>'' compare:''string<sub>2</sub>''] | Objective-C (NSString * only) | |
LLT(''string<sub>1</sub>'',''string<sub>2</sub>'')LLE(''string<sub>1</sub>'',''string<sub>2</sub>'')LGT(''string<sub>1</sub>'',''string<sub>2</sub>'')LGE(''string<sub>1</sub>'',''string<sub>2</sub>'') | Fortran[5] | |
''string<sub>1</sub>''.localeCompare(''string<sub>2</sub>'') | JavaScript | |
{{codett|2=go|bytes.Compare([]byte(}}''string<sub>1</sub>''{{codett|2=go|), []byte(}}''string<sub>2</sub>'')) | Go | |
string compare ''string<sub>1</sub>'' ''string<sub>2</sub>'' | Tcl | |
compare(''string<sub>1</sub>'',''string<sub>2</sub>'',''count'') | PL/I[6] | |
''string<sub>1</sub>''.cmp(''string<sub>2</sub>'') | Rust[7] |
"hello" cmp "world"; # returns -1
cmp("hello", "world") # returns -1
"hello" cmp "world"; # returns Less"world" cmp "hello"; # returns More"hello" cmp "hello"; # returns Same
| Definition | string<sub>1</sub> OP string<sub>2</sub> OR (compare string<sub>1</sub> string<sub>2</sub>) returns Boolean. | |
|---|---|---|
| Description | Lexicographically compares two strings using a relational operator or function. Boolean result returned. |
| Format | Languages | |
|---|---|---|
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and | Pascal, Object Pascal (Delphi), OCaml, Seed7, Standard ML, BASIC, VB, VB .NET, F# | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and ; Also: and | ALGOL 68 | |
(stringOP? ''string<sub>1</sub>'' ''string<sub>2</sub>''), where OP can be any of and (operators starting with '-ci' are case-insensitive) | Scheme | |
(stringOP ''string<sub>1</sub>'' ''string<sub>2</sub>''), where OP can be any of and (operators starting with '' are case-insensitive) | Scheme (SRFI 13) | |
(stringOP ''string<sub>1</sub>'' ''string<sub>2</sub>''), where OP can be any of and (the verbal operators are case-insensitive) | Common Lisp | |
(stringOP ''string<sub>1</sub>'' ''string<sub>2</sub>''), where OP can be any of and | ISLISP | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and [8] | Rexx | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and [9] | PL/I | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and | Ada | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and | Erlang | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and | Haskell | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and | Perl, Raku | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and | C++ (STL), C#, D, Go, JavaScript, Python, PHP, Ruby, Rust,[10] Swift | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and (operators starting with '' are case-sensitive) | Windows PowerShell | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and | Lua | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and | Smalltalk | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'', where OP can be any of and and | Fortran[11] | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'' where OP can be any of as well as worded equivalents | COBOL | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'' where OP can be any of and | Cobra | |
''string<sub>1</sub>'' OP ''string<sub>2</sub>'' is available in the syntax, but means comparison of the pointers pointing to the strings, not of the string contents. Use the Compare (integer result) function. | C, Java | |
''string<sub>1</sub>''.METHOD(''string<sub>2</sub>'') where METHOD is any of eq, ne, gt, lt, ge, le | Rust |
"art" gt "painting"; # returns False"art" lt "painting"; # returns True
"hello" -gt "world" # returns false
See also: Concatenation.
| Definition | concatenate(string<sub>1</sub>,string<sub>2</sub>) returns string. | |
|---|---|---|
| Description | Concatenates (joins) two strings to each other, returning the combined string. Some languages like C have mutable strings, so really the second string is being appended to the first string and the mutated string is returned. |
| Format | Languages | |
|---|---|---|
''string<sub>1</sub>'' ''adjacent_to'' ''string<sub>2</sub>'' | Rexx (abutment, equivalent to ''string<sub>1</sub>'' || ''string<sub>2</sub>'') | |
''string<sub>1</sub>'' ''whitespace'' ''string<sub>2</sub>'' | Rexx (equivalent to ''string<sub>1</sub>'' || ' ' || ''string<sub>2</sub>'') | |
''string<sub>1</sub>'' & ''string<sub>2</sub>'' | Ada, FreeBASIC, Seed7, BASIC, VB, VB .NET, COBOL (between literals only) | |
[[strcat]](''string<sub>1</sub>'', ''string<sub>2</sub>'') | C, C++ ([[character (computing)|char]] [[Pointer (computer programming)|*]] only)[12] | |
''string<sub>1</sub>'' . ''string<sub>2</sub>'' | Perl, PHP | |
''string<sub>1</sub>'' + ''string<sub>2</sub>'' | ALGOL 68, C++ (STL), C#, Cobra, FreeBASIC, Go, Pascal, Object Pascal (Delphi), Java, JavaScript, Windows PowerShell, Python, Ruby, Rust,[13] F#, Swift, Turing, VB | |
''string<sub>1</sub>'' ~ ''string<sub>2</sub>'' | D, Raku | |
(string-append ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Scheme, ISLISP | |
(concatenate 'string ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Common Lisp | |
(str ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Clojure | |
''string<sub>1</sub>'' <nowiki>||</nowiki> ''string<sub>2</sub>'' | Rexx, SQL, PL/I | |
''string<sub>1</sub>'' // ''string<sub>2</sub>'' | Fortran | |
''string<sub>1</sub>'' ++ ''string<sub>2</sub>'' | Erlang, Haskell | |
''string<sub>1</sub>'' ^ ''string<sub>2</sub>'' | OCaml, Standard ML, F# | |
[''string<sub>1</sub>'' stringByAppendingString:''string<sub>2</sub>''] | Objective-C (NSString * only) | |
''string<sub>1</sub>'' .. ''string<sub>2</sub>'' | Lua | |
''string<sub>1</sub>'', ''string<sub>2</sub>'' | Smalltalk, APL | |
''string<sub>1</sub>'' ''string<sub>2</sub>'' | SNOBOL | |
''string<sub>1</sub>string<sub>2</sub>'' | Bash | |
''string<sub>1</sub>'' <> ''string<sub>2</sub>'' | Mathematica | |
| concat string1 string2 | Tcl |
"abc" . "def"; # returns "abcdef""Perl " . 5; # returns "Perl 5"
"abc" ~ "def"; # returns "abcdef""Perl " ~ 6; # returns "Perl 6"
| Definition | contains(''string'',''substring'') returns boolean | |
|---|---|---|
| Description | Returns whether string contains substring as a substring. This is equivalent to using Find and then detecting that it does not result in the failure condition listed in the third column of the Find section. However, some languages have a simpler way of expressing this test. | |
| Related | Find |
| Format | Languages | |
|---|---|---|
''string_in_string''(''string'', '''loc int''', ''substring'') | ALGOL 68 | |
''ContainsStr''(''string'', ''substring'') | Object Pascal (Delphi) | |
strstr(''string'', ''substring'') != NULL | C, C++ (char * only) | |
''string''.Contains(''substring'') | C#, VB .NET, Windows PowerShell, F# | |
''string''.contains(''substring'') | Cobra, Java (1.5+), Raku, Rust,[14] C++ (C++23)[15] | |
''string''.indexOf(''substring'') >= 0 | JavaScript | |
strpos(''string'', ''substring'') !== false | PHP | |
str_contains(''string'', ''substring'') | PHP (8+) | |
pos(''string'', ''substring'') <> 0 | Seed7 | |
''substring'' in ''string'' | Cobra, Python (2.3+) | |
string.find(''string'', ''substring'') ~= nil | Lua | |
''string''.include?(''substring'') | Ruby | |
Data.List.isInfixOf ''substring'' ''string'' | Haskell (GHC 6.6+) | |
''string'' includesSubstring: ''substring'' | Smalltalk (Squeak, Pharo, Smalltalk/X) | |
String.isSubstring ''substring'' ''string'' | Standard ML | |
(search ''substring'' ''string'') | Common Lisp | |
{{codett|2=lisp|(not (null (string-index}} ''substring'' ''string''))) | ISLISP | |
(substring? ''substring'' ''string'') | Clojure | |
! StringFreeQ[''string'', ''substring''] | Mathematica | |
index(''string'', ''substring'', ''startpos'')>0 | Fortran, PL/I[16] | |
index(''string'', ''substring'', ''occurrence'')>0 | Pick Basic | |
strings.Contains(''string'', ''substring'') | Go | |
''string''.find(''substring'') != string::npos | C++ | |
[''string'' containsString:''substring''] | Objective-C (NSString * only, iOS 8+/OS X 10.10+) | |
''string''.rangeOfString(''substring'') != nil | Swift (Foundation) | |
āØ/''substring''ā·''string'' | APL |
¢ Example in ALGOL 68 ¢ string in string("e", loc int, "Hello mate"); ¢ returns true ¢ string in string("z", loc int, "word"); ¢ returns false ¢
"e" in "Hello mate" # returns true"z" in "word" # returns false
"Good morning!".contains('z') # returns False"Ā”Buenos dĆas!".contains('Ć'); # returns True
Tests if two strings are equal. See also
| Format | Languages | |
|---|---|---|
''string<sub>1</sub>'' == ''string<sub>2</sub>'' | Python, C++ (STL), C#, Cobra, Go, JavaScript (similarity), PHP (similarity), Ruby, Rust, Erlang, Haskell, Lua, D, Mathematica, Swift | |
''string<sub>1</sub>'' === ''string<sub>2</sub>'' | JavaScript, PHP | |
''string<sub>1</sub>'' == ''string<sub>2</sub>''''string<sub>1</sub>'' .EQ. ''string<sub>2</sub>'' | Fortran | |
strcmp(''string<sub>1</sub>'', ''string<sub>2</sub>'') == 0 | C | |
(string=? ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Scheme | |
(string= ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Common Lisp, ISLISP | |
''string<sub>1</sub>'' = ''string<sub>2</sub>'' | ALGOL 68, Ada, Object Pascal (Delphi), OCaml, Pascal, Rexx, Seed7, Standard ML, BASIC, VB, VB .NET, F#, Smalltalk, PL/I, COBOL | |
test ''string<sub>1</sub>'' = ''string<sub>2</sub>''[ ''string<sub>1</sub>'' = ''string<sub>2</sub>'' ] | Bourne Shell | |
''string<sub>1</sub>'' eq ''string<sub>2</sub>'' | Perl, Raku, Tcl | |
''string<sub>1</sub>''.equals(''string<sub>2</sub>'') | Cobra, Java | |
''string<sub>1</sub>''.Equals(''string<sub>2</sub>'') | C# | |
''string<sub>1</sub>'' -eq ''string<sub>2</sub>''[string]::Equals(''string<sub>1</sub>'', ''string<sub>2</sub>'') | Windows PowerShell | |
[''string<sub>1</sub>'' isEqualToString:''string<sub>2</sub>''][''string<sub>1</sub>'' isEqual:''string<sub>2</sub>''] | Objective-C (NSString * only) | |
''string<sub>1</sub>'' ā” ''string<sub>2</sub>'' | APL | |
''string<sub>1</sub>''.eq(''string<sub>2</sub>'') | Rust |
'hello' eq 'world' # returns 0'hello' eq 'hello' # returns 1
'hello' eq 'world' # returns False'hello' eq 'hello' # returns True
"hello" -eq "world" # returns false
| Definition | find(''string'',''substring'') returns integer | |
|---|---|---|
| Description | 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 |
| Format | Languages | If not found | |
|---|---|---|---|
string in string(substring, pos, ''string[startpos:]'') | ALGOL 68 | returns BOOL: TRUE or FALSE, and position in REF INT pos. | |
InStr(Ā«''startpos'',Ā»''string'',''substring'') | VB (positions start at 1) | returns 0 | |
INSTR$(''string'',''substring'') | BASIC (positions start at 1) | returns 0 | |
index(''string'',''substring'') | AWK | returns 0 | |
index(''string'',''substring''Ā«,''startpos''Ā») | Perl 5 | returns ā1 | |
index(''string'',''substring''Ā«,''startpos''Ā»)''string''.index(''substring'',Ā«,''startpos''Ā») | Raku | returns Nil | |
instr(Ā«''startpos'',Ā»''string'',''substring'') | FreeBASIC | returns 0 | |
strpos(''string'',''substring''Ā«,''startpos''Ā») | PHP | returns FALSE | |
locate(''string'', ''substring'') | Ingres | returns string length + 1 | |
strstr(''string'', ''substring'') | C, C++ ([[character (computing)|char]] [[Pointer (computer programming)|*]] only, returns pointer to first character) | returns NULL | |
std.string.indexOf(''string'', ''substring'') | D | returns ā1 | |
pos(''string'', ''substring''Ā«, ''startpos''Ā») | Seed7 | returns 0 | |
strings.Index(''string'', ''substring'') | Go | returns ā1 | |
pos(''substring'', ''string'') | Pascal, Object Pascal (Delphi) | returns 0 | |
pos(''substring'', ''string''Ā«,''startpos''Ā») | Rexx | returns 0 | |
''string''.find(''substring''Ā«,''startpos''Ā») | C++ (STL) | returns std::string::npos | |
''string''.find(''substring''Ā«,''startpos''Ā«,''endpos''»») | Python | returns ā1 | |
''string''.index(''substring''«,''startpos''«,''endpos''»») | raises ValueError | ||
''string''.index(''substring''Ā«,''startpos''Ā») | Ruby | returns nil | |
''string''.indexOf(''substring''Ā«,''startpos''Ā») | Java, JavaScript | returns ā1 | |
''string''.IndexOf(''substring''Ā«,''startpos''Ā«, ''charcount''»») | VB .NET, C#, Windows PowerShell, F# | returns ā1 | |
string:str(''string'', ''substring'') | Erlang | returns 0 | |
(string-contains ''string'' ''substring'') | Scheme (SRFI 13) | returns #f | |
(search ''substring'' ''string'') | Common Lisp | returns NIL | |
(string-index ''substring'' ''string'') | ISLISP | returns nil | |
List.findIndex (List.isPrefixOf ''substring'') (List.tails ''string'') | Haskell (returns only index) | returns Nothing | |
Str.search_forward (Str.regexp_string ''substring'') ''string'' 0 | OCaml | raises Not_found | |
Substring.size (#1 (Substring.position ''substring'' (Substring.full ''string''))) | Standard ML | returns string length | |
[''string'' rangeOfString:''substring''].location | Objective-C (NSString * only) | returns NSNotFound | |
string.find(''string'', ''substring'')(''string''):find(''substring'') | Lua | returns nil | |
''string'' indexOfSubCollection: ''substring'' startingAt: ''startpos'' ifAbsent: ''aBlock''''string'' findString: ''substring'' startingAt: ''startpos'' | Smalltalk (Squeak, Pharo) | evaluate aBlock which is a block closure (or any object understanding value) returns 0 | |
startpos = INDEX(''string'', ''substring'' Ā«,''back''Ā» Ā«, ''kind''Ā») | Fortran | returns 0 if substring is not in string; returns LEN(string)+1 if substring is empty | |
POSITION(''substring'' IN ''string'') | SQL | returns 0 (positions start at 1) | |
index(''string'', ''substring'', ''startpos'') | PL/I | returns 0 (positions start at 1) | |
index(''string'', ''substring'', ''occurrence'') | Pick Basic | returns 0 if occurrence of substring is not in string; (positions start at 1) | |
''string''.indexOf(''substring''Ā«,''startpos''Ā«, ''charcount''»») | Cobra | returns ā1 | |
string first ''substring string startpos'' | Tcl | returns ā1 | |
(''substring''ā·''string'')ā³1 | APL | returns 1 + the last position in string | |
''string''.find(''substring'') | Rust[17] | returns None |
Examples
| Definition | find_character(''string'',''char'') returns integer | |
|---|---|---|
| Description | Returns the position of the start of the first occurrence of the character char in string. If the character 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. This can be accomplished as a special case of
| |
| Related | find |
| Format | Languages | If not found | |
|---|---|---|---|
char in string(char, pos, ''string[startpos:]'') | ALGOL 68 | returns : or, and position in . | |
instr(''string'', any ''char''Ā«,''startpos''Ā») (char, can contain more them one char, in which case the position of the first appearance of any of them is returned.) | FreeBASIC | returns 0 | |
strchr(''string'',''char'') | C, C++ ([[character (computing)|char]] [[Pointer (computer programming)|*]] only, returns pointer to character) | returns | |
std.string.find(''string'', ''dchar'') | D | returns ā1 | |
''string''.find(''char''Ā«,''startpos''Ā») | C++ (STL) | returns | |
pos(''string'', ''char''Ā«, ''startpos''Ā») | Seed7 | returns 0 | |
strings.IndexRune(''string'',''char'') | Go | returns ā1 | |
''string''.indexOf(''char''Ā«,''startpos''Ā») | Java, JavaScript | returns ā1 | |
''string''.IndexOf(''char''Ā«,''startpos''Ā«, ''charcount''»») | VB .NET, C#, Windows PowerShell, F# | returns ā1 | |
(position ''char'' ''string'') | Common Lisp | returns | |
(char-index ''char'' ''string'') | ISLISP | returns | |
List.elemIndex ''char'' ''string'' | Haskell (returns Just ''index'') | returns | |
String.index ''string'' ''char'' | OCaml | raises | |
position = SCAN (''string'', ''set'' Ā«, ''back''Ā» Ā«, ''kind''Ā»)position = VERIFY (''string'', ''set'' Ā«, ''back''Ā» Ā«, ''kind''Ā»){{ref|Fortran find|[a]}} | Fortran | returns zero | |
''string'' indexOf: ''char'' ifAbsent: aBlock''string'' indexOf: ''char''''string'' includes: ''char'' | Smalltalk | evaluate aBlock which is a BlockClosure (or any object understanding value)returns 0 returns true or false | |
index(''string'', ''char'', ''startpos'') | PL/I[18] | returns 0 (positions start at 1) | |
''string''.index(?''char'') | Ruby | returns | |
strpos(''string'',''char'',''startpos'') | PHP | returns | |
''string''.indexOf(''char''Ā«,''startpos''Ā«, ''charcount''»») | Cobra | returns ā1 | |
''string''ā³''char'' | APL | returns 1 + the last position in string | |
''string''.find(''substring'') | Rust | returns |
See also: printf format string.
| Definition | format(''formatstring'', ''items'') returns string | |
|---|---|---|
| Description | Returns the formatted string representation of one or more items. |
| Format | Languages | Format string syntax | |
|---|---|---|---|
associate(''file'', ''string''); [[putf]](''file'', ''$formatstring$'', ''items'') | ALGOL 68 | ALGOL | |
Format(''item'', ''formatstring'') | VB | | |
[[sprintf]](''formatstring'', ''items'') | Perl, PHP, Raku, Ruby | C | |
item.fmt(''formatstring'') | Raku | C | |
io_lib:format(''formatstring'', ''items'') | Erlang | | |
[[sprintf]](''outputstring'', ''formatstring'', ''items'') | C | C | |
std::format(''formatstring'', ''items'') | C++ (C++20) | Python | |
std.string.format(''formatstring'', ''items'') | D | C | |
Format(''formatstring'', ''items'') | Object Pascal (Delphi) | | |
fmt.Sprintf(''formatstring'', ''items'') | Go | C | |
[[printf (Unix)|printf]] ''formatstring'' ''items'' | Unix | C | |
''formatstring'' % (''items'') | Python, Ruby | C | |
''formatstring''.format(''items'') | Python | .NET | |
f''formatstring'' | Python 3 | ||
Printf.sprintf ''formatstring''[21] ''items'' | OCaml, F# | C | |
Text.Printf.printf ''formatstring'' ''items'' | Haskell (GHC) | C | |
''formatstring'' printf: ''items'' | Smalltalk | C | |
String.format(''formatstring'', ''items'') | Java | C | |
String.Format(''formatstring'', ''items'') | VB .NET, C#, F# | .NET | |
(format ''formatstring'' ''items'') | Scheme (SRFI 28) | Lisp | |
([[Format (Common Lisp)|format]] nil ''formatstring'' ''items'') | Common Lisp | Lisp | |
(format ''formatstring'' ''items'') | Clojure | Lisp | |
''formatstring'' -f ''items'' | Windows PowerShell | .NET | |
[NSString stringWithFormat:''formatstring'', ''items''] | Objective-C (NSString * only) | C | |
String(format:''formatstring'', ''items'') | Swift (Foundation) | C | |
string.format(''formatstring'', ''items'')(''formatstring''):format(''items'') | Lua | C | |
WRITE (''outputstring'', ''formatstring'') ''items'' | Fortran | Fortran | |
put string(''string'') edit(''items'')(''format'') | PL/I | PL/I (similar to Fortran) | |
String.format(''formatstring'', ''items'') | Cobra | .NET | |
format ''formatstring items'' | Tcl | C | |
''formatnumbers'' ā ''items''''formatstring'' āFMT ''items'' | APL | APL | |
format!(''formatstring'', ''items'') | Rust[22] | Python |
sprintf "My %s costs \$%.2f", "pen", 19.99; # returns "My pen costs $19.99"1.fmt("%04d"); # returns "0001"
"My %s costs $%.2f" % ("pen", 19.99); # returns "My pen costs $19.99""My costs $".format("pen", 19.99); # returns "My pen costs $19.99"
pen = "pen"f"My costs " #returns "My pen costs 19.99"
Tests if two strings are not equal. See also
| Format | Languages | |
|---|---|---|
''string<sub>1</sub>'' '''ne''' ''string<sub>2</sub>''''string<sub>1</sub>'' NE ''string<sub>2</sub>'' | ALGOL 68 ā The operator "ne" occurs in bold type-font. | |
''string<sub>1</sub>'' /= ''string<sub>2</sub>'' | ALGOL 68, Ada, Erlang, Fortran, Haskell | |
''string<sub>1</sub>'' <> ''string<sub>2</sub>'' | BASIC, VB, VB .NET, Pascal, Object Pascal (Delphi), OCaml, PHP, Seed7, Standard ML, F#, COBOL, Cobra, Python 2 (deprecated) | |
''string<sub>1</sub>'' # ''string<sub>2</sub>'' | BASIC (some implementations) | |
''string<sub>1</sub>'' ne ''string<sub>2</sub>'' | Perl, Raku | |
(string<> ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Scheme (SRFI 13) | |
(string/= ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Common Lisp | |
(string/= ''string<sub>1</sub>'' ''string<sub>2</sub>'') | ISLISP | |
(not= ''string<sub>1</sub>'' ''string<sub>2</sub>'') | Clojure | |
''string<sub>1</sub>'' != ''string<sub>2</sub>'' | C++ (STL), C#, Go, JavaScript (not similar), PHP (not similar), Python, Ruby, Rust, Swift, D, Mathematica | |
''string<sub>1</sub>'' !== ''string<sub>2</sub>'' | JavaScript, PHP | |
''string<sub>1</sub>'' \= ''string<sub>2</sub>'' | Rexx | |
''string<sub>1</sub>'' ¬= ''string<sub>2</sub>'' | PL/I | |
test ''string<sub>1</sub>'' != ''string<sub>2</sub>''[ ''string<sub>1</sub>'' != ''string<sub>2</sub>'' ] | Bourne Shell | |
''string<sub>1</sub>'' -ne ''string<sub>2</sub>''{{codett|-not [string]::Equals(|ps1}}''string<sub>1</sub>'', ''string<sub>2</sub>'') | Windows PowerShell | |
''string<sub>1</sub>'' ~= ''string<sub>2</sub>'' | Lua, Smalltalk | |
''string<sub>1</sub>'' ⢠''string<sub>2</sub>'' | APL | |
''string<sub>1</sub>''.ne(''string<sub>2</sub>'') | Rust |
'hello' ne 'world' # returns 1
'hello' ne 'world' # returns True
"hello" -ne "world" # returns true
see
see
see
see
| Definition | join(''separator'', ''list_of_strings'') returns a list of strings joined with a separator | |
|---|---|---|
| Description | Joins the list of strings into a new string, with the separator string between each of the substrings. Opposite of split. | |
| Related | sprintf |
| Format | Languages | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
std.string.join(''array_of_strings'', ''separator'') | D | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string:join(''list_of_strings'', ''separator'') | Erlang | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
join(''separator'', ''list_of_strings'') | Perl, PHP, Raku | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
implode(''separator'', ''array_of_strings'') | PHP | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
''separator''.join(''sequence_of_strings'') | Python, Swift 1.x | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
''array_of_strings''.join(''separator'') | Ruby, JavaScript, Raku, Rust[23] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(string-join ''array_of_strings'' ''separator'') | Scheme (SRFI 13) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
([[Format (Common Lisp)|format]] nil "~{~a~^''separator''~}" ''array_of_strings'') | Common Lisp | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(clojure.string/join ''separator'' ''list_of_strings'')(apply str (interpose ''separator'' ''list_of_strings'')) | Clojure | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
strings.Join(''array_of_strings'', ''separator'') | Go | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
join(''array_of_strings'', ''separator'') | Seed7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String.concat ''separator'' ''list_of_strings'' | OCaml | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String.concatWith ''separator'' ''list_of_strings'' | Standard ML | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Data.List.intercalate ''separator'' ''list_of_strings'' | Haskell (GHC 6.8+) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Join(''array_of_strings'', ''separator'') | VB | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String.Join(''separator'', ''array_of_strings'') | VB .NET, C#, F# | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String.join(''separator'', ''array_of_strings'') | Java 8+ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&{$OFS=''$separator''; "''$array_of_strings''"}''array_of_strings'' -join ''separator'' | Windows PowerShell | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[''array_of_strings'' componentsJoinedByString:''separator''] | Objective-C (NSString * only) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
table.concat(''table_of_strings'', ''separator'') | Lua | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{{codett|<nowiki>{|String streamContents: [ :stream |</nowiki>|smalltalk}} ''collectionOfAnything'' asStringOn: stream delimiter: ''separator'' <nowiki>]</nowiki>''collectionOfAnything'' joinUsing: ''separator''|Smalltalk (Squeak, Pharo)|-| ''array_of_strings''.join(''separator''Ā«, ''final_separator''Ā»)|Cobra|-| ''sequence_of_strings''.joinWithSeparator(''separator'')|Swift 2.x|-| 1āā''separator'',ĀØ''list_of_strings''|APL|}
join('-', ('a', 'b', 'c')); # 'a-b-c'
"-".join(["a", "b", "c"]) # 'a-b-c'
["a", "b", "c"].join("-") # 'a-b-c'
lastindexofsee
left
"Hello, there!".substr(0, 6); # returns "Hello,"
lensee
length
string:len("hello"). % returns 5string:len(""). % returns 0
length("hello"); # returns 5length(""); # returns 0
"".chars; chars ""; # both return 0"".codes; codes ""; # both return 0
locatesee
Lowercase
|
str::chars method iterates over code points and the std::iter::Iterator::nth method on iterators returns the zero-indexed nth value from the iterator, or None.operator<=> method on a string returns a std::strong_ordering object (otherwise std::weak_ordering): less, equal (same as equivalent), or greater..TRUE. or .FALSE.. These functions are based on the ASCII collating sequence.Ord::cmp method on a string returns an Ordering: Less, Equal, or Greater.eq, ne are implemented by the PartialEq trait, and the operators,,, and the methods lt, gt, le, ge are implemented by the PartialOrd trait.string<sub>1</sub>, which must have enough space to store the result+ operator is implemented by the Add trait.str::contains method.std::basic_string::contains method.str::find method.startpos is IBM extension.formatstring must be a fixed literal at compile time for it to have the correct type.std::format, which is imported by the Rust prelude so that it can be used under the name format.slice::join method.&str (string reference) can be indexed by various types of ranges, including Range (0..n), RangeFrom (n..), and RangeTo (..n) because they all implement the SliceIndex trait with str being the type being indexed.The str::get method is the non-panicking way to index. It returns None in the cases in which indexing would panic.
str::len method.str::chars method iterates over code points and the std::iter::Iterator::count method on iterators consumes the iterator and returns the total number of elements in the iterator.transform function exists in the std:: namespace. You must include the <algorithm> header file to use it. The tolower and toupper functions are in the global namespace, obtained by the <ctype.h> header file. The std::tolower and std::toupper names are overloaded and cannot be passed to std::transform without a cast to resolve a function overloading ambiguity, e.g. std::transform(''string''.begin, ''string''.end, ''result''.begin, (int (*)(int))std::tolower);[[std::string]] only, result is stored in string result which is at least as long as string, and may or may not be string itselfstr::to_lowercase method.str::replace method.str::chars method iterates over code points, the std::iter::Iterator::rev method on reversible iterators (std::iter::DoubleEndedIterator) creates a reversed iterator, and the std::iter::Iterator::collect method consumes the iterator and creates a collection (which here is specified as a String with the turbofish syntax) from the iterator's elements.str::rfind method.str::split and str::rsplit methods.[[std::string]] only, result is stored in string result which is at least as long as string, and may or may not be string itselfstr::to_uppercase method returns a newly allocated String with any lowercase characters changed to uppercase ones following the Unicode rules.str::trim method returns a reference to the original &str.