String Function
   HOME

TheInfoList



OR:

String functions are used in computer
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
s to manipulate a string or query information about a string (some do both). Most programming languages that have a string
datatype In computer science and computer programming, a data type (or simply type) is a set of possible values and a set of allowed operations on it. A data type tells the compiler or interpreter how the programmer intends to use the data. Most progra ...
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 Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
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 In formal language, formal language theory and computer programming, string concatenation is the operation of joining character string (computer science), character strings wikt:end-to-end, end-to-end. For example, the concatenation of "sno ...
below. The most basic example of a string function is the length(string) function. This function returns the length of a
string literal A string literal (computer programming), literal or anonymous string is a String (computer science), string value in the source code of a computer program. Modern Computer programming, programming languages commonly use a quoted sequence of charact ...
. :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.


Common string functions (multi language reference)

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. Note, string
concatenation In formal language, formal language theory and computer programming, string concatenation is the operation of joining character string (computer science), character strings wikt:end-to-end, end-to-end. For example, the concatenation of "sno ...
and
regular expressions A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or ...
are handled in separate pages. Statements in
guillemets Guillemets (, also , , ) are a pair of punctuation marks in the form of sideways double chevrons, and , used as quotation marks in a number of languages. In some of these languages "single" guillemets, and , are used for a quotation inside an ...
(« … ») are optional.


CharAt

var MyStr: string = 'Hello, World'; MyChar: Char; begin MyChar := MyStr // 'e'
# Example in ALGOL 68 #
"Hello, World"              // 'e'
// Example in C #include // for printf char MyStr[] = "Hello, World"; printf("%c", *(MyStr+1)); // 'e' printf("%c", *(MyStr+7)); // 'W' printf("%c", MyStr[11]); // 'd' printf("%s", MyStr); // 'Hello, World' printf("%s", "Hello(2), World(2)"); // 'Hello(2), World(2)' // Example in C++ #include // for "cout" #include // for "string" data type using namespace std; char MyStr1[] = "Hello(1), World(1)"; string MyStr2 = "Hello(2), World(2)"; cout << "Hello(3), World(3)"; // 'Hello(3), World(3)' cout << MyStr2[6]; // '2' cout << MyStr1.substr (5, 3); // '(1)' // Example in C# "Hello, World" // 'l' # Example in Perl 5 substr("Hello, World", 1, 1); # 'e' # Examples in Python "Hello, World" # 'l' "Hello, World" 3 # 'r' # Example in Raku "Hello, World".substr(1, 1); # 'e' ' Example in Visual Basic Mid("Hello, World",2,1) ' Example in Visual Basic .NET "Hello, World".Chars(2) ' "l"c " Example in Smalltalk " 'Hello, World' at: 2. "$e" //Example in Rust "Hello, World".chars().nth(2); // Some('l')


Compare (integer result)

# Example in Perl 5 "hello" cmp "world"; # returns -1 # Example in Python cmp("hello", "world") # returns -1 # Examples in Raku "hello" cmp "world"; # returns Less "world" cmp "hello"; # returns More "hello" cmp "hello"; # returns Same /** Example in Rexx */ compare("hello", "world") /* returns index of mismatch: 1 */ ; Example in Scheme (use-modules (srfi srfi-13)) ; returns index of mismatch: 0 (string-compare "hello" "world" values values values)


Compare (relational operator-based, Boolean result)

% Example in Erlang "hello" > "world". % returns false # Example in Raku "art" gt "painting"; # returns False "art" lt "painting"; # returns True # Example in Windows PowerShell "hello" -gt "world" # returns false ;; Example in Common Lisp (string> "art" "painting") ; returns nil (string< "art" "painting") ; returns non nil


Concatenation

'abc' + 'def'; // returns "abcdef" // Example in C# "abc" + "def"; // returns "abcdef" ' Example in Visual Basic "abc" & "def" ' returns "abcdef" "abc" + "def" ' returns "abcdef" "abc" & Null ' returns "abc" "abc" + Null ' returns Null // Example in D "abc" ~ "def"; // returns "abcdef" ;; Example in common lisp (concatenate 'string "abc " "def " "ghi") ; returns "abc def ghi" # Example in Perl 5 "abc" . "def"; # returns "abcdef" "Perl " . 5; # returns "Perl 5" # Example in Raku "abc" ~ "def"; # returns "abcdef" "Perl " ~ 6; # returns "Perl 6"


Contains

¢ Example in
ALGOL 68 ALGOL 68 (short for ''Algorithmic Language 1968'') is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously de ...
¢ string in string("e", loc int, "Hello mate"); ¢ returns true ¢ string in string("z", loc int, "word"); ¢ returns false ¢ // Example In C# "Hello mate".Contains("e"); // returns true "word".Contains("z"); // returns false # Example in Python "e" in "Hello mate" # returns true "z" in "word" # returns false # Example in Raku "Good morning!".contains('z') # returns False "¡Buenos días!".contains('í'); # returns True " Example in Smalltalk " 'Hello mate' includesSubstring: 'e' " returns true " 'word' includesSubstring: 'z' " returns false "


Equality

Tests if two strings are equal. See also #Compare and #Compare. Note that doing equality checks via a generic Compare with integer result is not only confusing for the programmer but is often a significantly more expensive operation; this is especially true when using " C-strings". // Example in C# "hello"

"world" // returns false
' Example in Visual Basic "hello" = "world" ' returns false # Examples in Perl 5 'hello' eq 'world' # returns 0 'hello' eq 'hello' # returns 1 # Examples in Raku 'hello' eq 'world' # returns False 'hello' eq 'hello' # returns True # Example in Windows PowerShell "hello" -eq "world" # returns false ⍝ Example in APL 'hello' ≡ 'world' ⍝ returns 0


Find

; Examples in Common Lisp (search "e" "Hello mate") ; returns 1 (search "z" "word") ; returns NIL // Examples in C# "Hello mate".IndexOf("e"); // returns 1 "Hello mate".IndexOf("e", 4); // returns 9 "word".IndexOf("z"); // returns -1 # Examples in Raku "Hello, there!".index('e') # returns 1 "Hello, there!".index('z') # returns Nil ; Examples in Scheme (use-modules (srfi srfi-13)) (string-contains "Hello mate" "e") ; returns 1 (string-contains "word" "z") ; returns #f ' Examples in Visual Basic InStr("Hello mate", "e") ' returns 2 InStr(5, "Hello mate", "e") ' returns 10 InStr("word", "z") ' returns 0 " Examples in Smalltalk " 'Hello mate' indexOfSubCollection:'ate' "returns 8" 'Hello mate' indexOfSubCollection:'late' "returns 0" I'Hello mate' indexOfSubCollection:'late' ifAbsent:
99 99 may refer to: * 99 (number), the natural number following 98 and preceding 100 * one of the years 99 BC, AD 99, 1999, 2099, etc. Art, entertainment, and media * ''The 99'', a comic series based on Islamic culture Film, television and radio * ...
"returns 99" 'Hello mate' indexOfSubCollection:'late' ifAbsent:
self error The self is an individual as the object of that individual’s own reflective consciousness. Since the ''self'' is a reference by a subject to the same subject, this reference is necessarily Subjective character of experience, subjective. The sen ...
"raises an exception"


Find character

// Examples in C# "Hello mate".IndexOf('e'); // returns 1 "word".IndexOf('z') // returns -1 ; Examples in Common Lisp (position #\e "Hello mate") ; returns 1 (position #\z "word") ; returns NIL Given a set of characters, SCAN returns the position of the first character found, while VERIFY returns the position of the first character that does not belong to the set.


Format

// Example in C# String.Format("My costs ", "pen", 19.99); // returns "My pen costs $19.99" // Example in Object Pascal (Delphi) Format('My %s costs $%2f', pen', 19.99; // returns "My pen costs $19.99" // Example in Java String.format("My %s costs $%2f", "pen", 19.99); // returns "My pen costs $19.99" # Examples in Raku sprintf "My %s costs \$%.2f", "pen", 19.99; # returns "My pen costs $19.99" 1.fmt("%04d"); # returns "0001" # Example in Python "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" #Example in Python 3.6+ pen = "pen" f"My costs " #returns "My pen costs 19.99" ; Example in Scheme (format "My ~a costs $~1,2F" "pen" 19.99) ; returns "My pen costs $19.99"
/* 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" */


Inequality

Tests if two strings are not equal. See also #Equality. // Example in C# "hello" != "world" // returns true ' Example in Visual Basic "hello" <> "world" ' returns true ;; Example in Clojure (not= "hello" "world") ; ⇒ true # Example in Perl 5 'hello' ne 'world' # returns 1 # Example in Raku 'hello' ne 'world' # returns True # Example in Windows PowerShell "hello" -ne "world" # returns true


index

''see'' #Find


indexof

''see'' #Find


instr

''see'' #Find


instrrev

''see'' #rfind


join

{, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , std.string.join(''array_of_strings'', ''separator'') , D , - , string:join(''list_of_strings'', ''separator'') , Erlang , - , join(''separator'', ''list_of_strings'') ,
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, Raku , - , implode(''separator'', ''array_of_strings'') ,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , ''separator''.join(''sequence_of_strings'') ,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
1.x , - , ''array_of_strings''.join(''separator'') ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, Raku,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
, - , (string-join ''array_of_strings'' ''separator'') ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
(SRFI 13) , - , (
format Format may refer to: Printing and visual media * Text formatting, the typesetting of text elements * Paper formats, or paper size standards * Newspaper format, the size of the paper page Computing * File format, particular way that informatio ...
nil "~{~a~^''separator''~}" ''array_of_strings'')
,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, - , (clojure.string/join ''separator'' ''list_of_strings'')
(apply str (interpose ''separator'' ''list_of_strings''))
,
Clojure Clojure (, like ''closure'') is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system. The current development process is comm ...
, - , strings.Join(''array_of_strings'', ''separator'') , Go , - , join(''array_of_strings'', ''separator'') ,
Seed7 Seed7 is an extensible general-purpose programming language designed by Thomas Mertes. It is syntactically similar to Pascal and Ada. Along with many other features, it provides an extension mechanism. Daniel Zingaro"Modern Extensible Languages" ...
, - , String.concat ''separator'' ''list_of_strings'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, - , String.concatWith ''separator'' ''list_of_strings'' ,
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of the ...
, - , Data.List.intercalate ''separator'' ''list_of_strings'' ,
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
(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 Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
8+ , - , &{$OFS=''$separator''; "''$array_of_strings''"}, or
''array_of_strings'' -join ''separator''
,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, - , 'array_of_strings'' componentsJoinedByString:''separator''/code> ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only) , - , table.concat(''table_of_strings'', ''separator'') ,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , {, String streamContents: ''collectionOfAnything'' asStringOn: stream delimiter: ''separator'' /nowiki>
''collectionOfAnything'' joinUsing: ''separator''
,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
(
Squeak Squeak is an object-oriented, class-based, and reflective programming language. It was derived from Smalltalk-80 by a group that included some of Smalltalk-80's original developers, initially at Apple Computer, then at Walt Disney Imagineering, ...
,
Pharo Pharo is an open source, cross-platform implementation of the classic Smalltalk-80 programming language and runtime. It's based on the OpenSmalltalk virtual machine called Cog (VM), which evaluates a dynamic, reflective, and object-orient ...
) , - , ''array_of_strings''.join(''separator''«, ''final_separator''») , Cobra , - , ''sequence_of_strings''.joinWithSeparator(''separator'') ,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
2.x , - , 1↓∊''separator'',¨''list_of_strings'' , APL // Example in C# String.Join("-", {"a", "b", "c"}) // "a-b-c" " Example in Smalltalk " #('a' 'b' 'c') joinUsing: '-' " 'a-b-c' " # Example in Perl 5 join( '-', ('a', 'b', 'c')); # 'a-b-c' # Example in Raku .join('-'); # 'a-b-c' # Example in Python "-".join( a", "b", "c" # 'a-b-c' # Example in Ruby a", "b", "c"join("-") # 'a-b-c' ; Example in Scheme (use-modules (srfi srfi-13)) (string-join '("a" "b" "c") "-") ; "a-b-c"


lastindexof

''see'' #rfind


left

{, class="wikitable" , - style="background:#fffeed;" ! Definition , left(''string'',''n'') returns string , - ! Description , Returns the left ''n'' part of a string. If ''n'' is greater than the length of the string then most implementations return the whole string (exceptions exist – see code examples). Note that for variable-length encodings such as
UTF-8 UTF-8 is a variable-width encoding, variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit'' ...
,
UTF-16 UTF-16 (16-bit computing, 16-bit Unicode Transformation Format) is a character encoding capable of encoding all 1,112,064 valid code points of Unicode (in fact this number of code points is dictated by the design of UTF-16). The encoding is variab ...
or Shift-JIS, it can be necessary to remove string positions at the end, in order to avoid invalid strings. {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , string (string'First .. string'First + ''n'' - 1) ,
Ada Ada may refer to: Places Africa * Ada Foah, a town in Ghana * Ada (Ghana parliament constituency) * Ada, Osun, a town in Nigeria Asia * Ada, Urmia, a village in West Azerbaijan Province, Iran * Ada, Karaman, a village in Karaman Province, ...
, - , substr(''string'', 0, ''n'') ,
AWK AWK (''awk'') is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems. The AWK lang ...
(changes string),
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, Raku , - , LEFT$(''string'',''n'') ,
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
, VB , - , left(''string'',''n'') , , VB,
FreeBASIC FreeBASIC is a free and open source multiplatform compiler and programming language based on BASIC licensed under the GNU GPL for Microsoft Windows, protected-mode MS-DOS (DOS extender), Linux, FreeBSD and Xbox. The Xbox version is no longer m ...
, Ingres,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , strncpy(''string2'', ''string'', ''n'') ,
C standard library The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard.ISO/IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the original ANSI C standard, it wa ...
, - , ''string''.substr(0,''n'') ,
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
(STL), Raku , - , 'string'' substringToIndex:''n''/code> ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only) , - , (apply str (take ''n'' ''string'')) ,
Clojure Clojure (, like ''closure'') is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system. The current development process is comm ...
, - , ''string'' .. ''n''/code> , D , - , string:substr(''string'', ''start'', ''length'') , Erlang , - , (subseq ''string'' 0 ''n'') ,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, - , ''string'' ''n''/code> , Cobra, Go,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, - , left(''string'',''n'' «,''padchar''») ,
Rexx Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
, Erlang , - , ''string''
, ''n'' The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline ...

''string'' ..''n'' - 1/code> ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, - , ''string''
, ''n'' The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline ...
/code> ,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , ''string'' .. ''n''/code> ,
Seed7 Seed7 is an extensible general-purpose programming language designed by Thomas Mertes. It is syntactically similar to Pascal and Ada. Along with many other features, it provides an extension mechanism. Daniel Zingaro"Modern Extensible Languages" ...
, - , ''string''.Substring(0,''n'') , VB .NET, C#,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, F# , - , leftstr(''string'', ''n'') ,
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, Fren ...
,
Object Pascal Object Pascal is an extension to the programming language Pascal (programming language), Pascal that provides object-oriented programming (OOP) features such as Class (computer programming), classes and Method (computer programming), methods. ...
(
Delphi Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracle ...
) , - , ''copy'' (''string'',1,''n'') ,
Turbo Pascal Turbo Pascal is a software development system that includes a compiler and an integrated development environment (IDE) for the Pascal (programming language), Pascal programming language running on CP/M, CP/M-86, and DOS. It was originally develo ...
, - , ''string''.substring(0,''n'') ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , (string-take ''string'' ''n'') ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
(SRFI 13) , - , take ''n'' ''string'' ,
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
, - , String.extract (''string'', ''n'', NONE) ,
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of the ...
, - , String.sub ''string'' 0 ''n'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
if n is larger than length of string, raises Invalid_argument , - , ''string''. .''n''/code> , F# , - , string.sub(''string'', 1, ''n'')
(''string''):sub(1, ''n'')
,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , ''string'' first: ''n'' ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
(
Squeak Squeak is an object-oriented, class-based, and reflective programming language. It was derived from Smalltalk-80 by a group that included some of Smalltalk-80's original developers, initially at Apple Computer, then at Walt Disney Imagineering, ...
,
Pharo Pharo is an open source, cross-platform implementation of the classic Smalltalk-80 programming language and runtime. It's based on the OpenSmalltalk virtual machine called Cog (VM), which evaluates a dynamic, reflective, and object-orient ...
) , - , ''string''(:''n'') , Fortran , - , StringTake 'string'', ''n''/code> ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
if n is larger than length of string, throw the message "StringTake::take:" , - , ''string'' («FUNCTION» LENGTH(''string'') - ''n'':''n'') ,
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, - , ''string''.substring(0, ''n'') , Cobra , - , ''n''↑''string''. , APL , - , ''string'' ..n/code>
''string'' .n/code>
''string''.get(0..n)
''string''.get(..n) ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
In Rust, strings are indexed in terms of byte offsets and there is a runtime panic if the index is out of bounds or if it would result in invalid
UTF-8 UTF-8 is a variable-width encoding, variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit'' ...
. A &str (string reference) can b
indexed
by various types of ranges, includin

(0..n)

(n..), an

(..n) because they all implement th

trait with str being the type being indexed. Th

method is the non-panicking way to index. It returns None in the cases in which indexing would panic.
# Example in Raku "Hello, there!".substr(0, 6); # returns "Hello," /* Examples in Rexx */ left("abcde", 3) /* returns "abc" */ left("abcde", 8) /* returns "abcde " */ left("abcde", 8, "*") /* returns "abcde***" */ ; Examples in Scheme (use-modules (srfi srfi-13)) (string-take "abcde", 3) ; returns "abc" (string-take "abcde", 8) ; error ' Examples in Visual Basic Left("sandroguidi", 3) ' returns "san" Left("sandroguidi", 100) ' returns "sandroguidi"


len

''see'' #length


length

{, class="wikitable" , - style="background:#fffeed;" ! Definition , length(''string'') returns an integer number , - ! Description , Returns the length of a string (not counting the null terminator or any other of the string's internal structural information). An empty string returns a length of 0. {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Returns !! Languages , - , string'Length , ,
Ada Ada may refer to: Places Africa * Ada Foah, a town in Ghana * Ada (Ghana parliament constituency) * Ada, Osun, a town in Nigeria Asia * Ada, Urmia, a village in West Azerbaijan Province, Iran * Ada, Karaman, a village in Karaman Province, ...
, - , UPB string , ,
ALGOL 68 ALGOL 68 (short for ''Algorithmic Language 1968'') is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously de ...
, - , length(''string'') , , Ingres,
Perl 5 Perl is a family of two High-level programming language, high-level, General-purpose programming language, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it ...
,
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, Fren ...
,
Object Pascal Object Pascal is an extension to the programming language Pascal (programming language), Pascal that provides object-oriented programming (OOP) features such as Class (computer programming), classes and Method (computer programming), methods. ...
(
Delphi Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracle ...
),
Rexx Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
,
Seed7 Seed7 is an extensible general-purpose programming language designed by Thomas Mertes. It is syntactically similar to Pascal and Ada. Along with many other features, it provides an extension mechanism. Daniel Zingaro"Modern Extensible Languages" ...
, SQL,
PL/I PL/I (Programming Language One, pronounced and sometimes written PL/1) is a procedural, imperative computer programming language developed and published by IBM. It is designed for scientific, engineering, business and system programming. I ...
, - , len(''string'') , ,
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
,
FreeBASIC FreeBASIC is a free and open source multiplatform compiler and programming language based on BASIC licensed under the GNU GPL for Microsoft Windows, protected-mode MS-DOS (DOS extender), Linux, FreeBSD and Xbox. The Xbox version is no longer m ...
,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, Go,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , length(''string''), string:len(''string'') , , Erlang , - , Len(''string'') , , VB,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , ''string''.Length , Number of
UTF-16 UTF-16 (16-bit computing, 16-bit Unicode Transformation Format) is a character encoding capable of encoding all 1,112,064 valid code points of Unicode (in fact this number of code points is dictated by the design of UTF-16). The encoding is variab ...
code unit Character encoding is the process of assigning numbers to graphical characters, especially the written characters of human language, allowing them to be stored, transmitted, and transformed using digital computers. The numerical values that ...
s , VB .NET, C#,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, F# , - , chars(''string'')
''string''.chars , Number of graphemes (NFG) , Raku , - , codes(''string'')
''string''.codes , Number of Unicode code points , Raku , - , ''string''.size OR ''string''.length , Number of bytes ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, - ,
strlen The C programming language has a set of functions implementing operations on strings (character strings and byte strings) in its standard library. Various operations, such as copying, concatenation, tokenization and searching are supported. ...
(''string'')
, Number of bytes , C,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , ''string''.length() , ,
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
(STL) , - , ''string''.length , , Cobra, D,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , ''string''.length() , Number of
UTF-16 UTF-16 (16-bit computing, 16-bit Unicode Transformation Format) is a character encoding capable of encoding all 1,112,064 valid code points of Unicode (in fact this number of code points is dictated by the design of UTF-16). The encoding is variab ...
code unit Character encoding is the process of assigning numbers to graphical characters, especially the written characters of human language, allowing them to be stored, transmitted, and transformed using digital computers. The numerical values that ...
s ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, - , (string-length ''string'') , ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
, - , (length ''string'') , ,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
,
ISLISP ISLISP (also capitalized as ISLisp) is a programming language in the Lisp family standardized by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC) joint working group ISO/IEC JTC 1/SC 22/W ...
, - , (count ''string'') , ,
Clojure Clojure (, like ''closure'') is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system. The current development process is comm ...
, - , String.length ''string'' , ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, - , size ''string'' , ,
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of the ...
, - , length ''string'' , Number of Unicode code points ,
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
, - , ''string''.length , Number of
UTF-16 UTF-16 (16-bit computing, 16-bit Unicode Transformation Format) is a character encoding capable of encoding all 1,112,064 valid code points of Unicode (in fact this number of code points is dictated by the design of UTF-16). The encoding is variab ...
code units ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only) , - , ''string''.characters.count , Number of characters ,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(2.x) , - , count(''string'') , Number of characters ,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(1.2) , - , countElements(''string'') , Number of characters ,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(1.0–1.1) , - , string.len(''string'')
(''string''):len()
#''string''
, ,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , ''string'' size , ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
, - , LEN(''string''), or LEN_TRIM(''string'') , , Fortran , - , StringLength 'string''/code> , ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
, - , «FUNCTION» LENGTH(''string'') or «FUNCTION» BYTE-LENGTH(''string'') , number of characters and number of bytes, respectively ,
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, - , string length ''string'' , a decimal string giving the number of characters ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, - , ≢ ''string'' , , APL , - , ''string''.len() , Number of bytes ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
, - , ''string''.chars().count() , Number of Unicode code points ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
// Examples in C# "hello".Length; // returns 5 "".Length; // returns 0 # Examples in Erlang string:len("hello"). % returns 5 string:len(""). % returns 0 # Examples in Perl 5 length("hello"); # returns 5 length(""); # returns 0 # Examples in Raku "🏳️‍🌈".chars; chars "🏳️‍🌈"; # both return 1 "🏳️‍🌈".codes; codes "🏳️‍🌈"; # both return 4 "".chars; chars ""; # both return 0 "".codes; codes ""; # both return 0 ' Examples in Visual Basic Len("hello") ' returns 5 Len("") ' returns 0 //Examples in Objective-C "hello" Length //returns 5 "" Length //returns 0 -- Examples in Lua ("hello"):len() -- returns 5 #"" -- returns 0


locate

''see'' #Find


Lowercase

{, class="wikitable" , - style="background:#fffeed;" ! Definition , lowercase(''string'') returns string , - ! Description , Returns the string in lower case. {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , LCase(''string'') , VB , - , lcase(''string'') ,
FreeBASIC FreeBASIC is a free and open source multiplatform compiler and programming language based on BASIC licensed under the GNU GPL for Microsoft Windows, protected-mode MS-DOS (DOS extender), Linux, FreeBSD and Xbox. The Xbox version is no longer m ...
, - , lc(''string'') ,
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
, Raku , - , ''string''.lc , Raku , - , tolower(''char'') , C , - , std.string.toLower(''string'') , D , - , transform(''string''.begin(), ''string''.end(), ''result''.begin(), ::tolower)The transform function exists in the std:: namespace. You must include the header file to use it. The tolower and toupper functions are in the global namespace, obtained by the 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); ,
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
, - , lowercase(''string'') ,
Object Pascal Object Pascal is an extension to the programming language Pascal (programming language), Pascal that provides object-oriented programming (OOP) features such as Class (computer programming), classes and Method (computer programming), methods. ...
(
Delphi Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracle ...
) , - , strtolower(''string'') ,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , lower(''string'') ,
Seed7 Seed7 is an extensible general-purpose programming language designed by Thomas Mertes. It is syntactically similar to Pascal and Ada. Along with many other features, it provides an extension mechanism. Daniel Zingaro"Modern Extensible Languages" ...
, - , ${''string_param'',,} ,
Bash Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
, - ,
echo In audio signal processing and acoustics, an echo is a reflection of sound that arrives at the listener with a delay after the direct sound. The delay is directly proportional to the distance of the reflecting surface from the source and the list ...
"string" , tr 'A-Z' 'a-z'
,
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
, - , ''string''.lower() ,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, - , downcase(''string'') ,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , ''string''.downcase ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
only ASCII characters as Ruby lacks Unicode support , - , strings.ToLower(''string'') , Go , - , (string-downcase ''string'') ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
(R6RS),
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, - , (lower-case ''string'') ,
Clojure Clojure (, like ''closure'') is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system. The current development process is comm ...
, - , String.lowercase ''string'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, - , String.map Char.toLower ''string'' ,
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of the ...
, - , map Char.toLower ''string'' ,
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
, - , ''string''.toLowerCase() ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , to_lower(''string'') , Erlang , - , ''string''.ToLower() , VB .NET, C#,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, F# , - , ''string''.lowercaseString ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only),
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(Foundation) , - , string.lower(''string'')
(''string''):lower()
,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , ''string'' asLowercase ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
, - , LOWER(''string'') , SQL , - , lowercase(''string'') ,
PL/I PL/I (Programming Language One, pronounced and sometimes written PL/1) is a procedural, imperative computer programming language developed and published by IBM. It is designed for scientific, engineering, business and system programming. I ...
, - , ToLowerCase 'string''/code> ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
, - , «FUNCTION» LOWER-CASE(''string'') ,
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, - , ''string''.toLower , Cobra , - , string tolower ''string'' ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, - , ''string''.to_lowercase() ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
// Example in C# "Wiki means fast?".ToLower(); // "wiki means fast?" ; Example in Scheme (use-modules (srfi srfi-13)) (string-downcase "Wiki means fast?") ; "wiki means fast?" /* Example in C */ #include #include int main(void) { char string[] = "Wiki means fast?"; int i; for (i = 0; i < sizeof(string) - 1; ++i) { /* transform characters in place, one by one */ string = tolower(string ; } puts(string); /* "wiki means fast?" */ return 0; } # Example in Raku "Wiki means fast?".lc; # "wiki means fast?"


mid

''see'' #substring


partition

{, class="wikitable" , - style="background:#fffeed;" ! Definition , .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" , - style="text-align:left;" ! Format !! Languages !! Comments , - , ''string''.partition(''separator'') ,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
(1.9+) , , - , lists:partition(''pred'', ''string'') , Erlang , , - , split /(''separator'')/, ''string'', 2 ,
Perl 5 Perl is a family of two High-level programming language, high-level, General-purpose programming language, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it ...
, , - , split ''separator'', ''string'', 2
''string''.split( ''separator'', 2 ) , Raku , Separator does not have to be a regular expression # Examples in Python "Spam eggs spam spam and ham".partition('spam') # ('Spam eggs ', 'spam', ' spam and ham') "Spam eggs spam spam and ham".partition('X') # ('Spam eggs spam spam and ham', "", "") # Examples in Perl 5 / Raku split /(spam)/, 'Spam eggs spam spam and ham' ,2; # ('Spam eggs ', 'spam', ' spam and ham'); split /(X)/, 'Spam eggs spam spam and ham' ,2; # ('Spam eggs spam spam and ham');


replace

{, class="wikitable" , - style="background:#fffeed;" ! Definition , replace(''string'', ''find'', ''replace'') returns string , - ! Description , Returns a string with ''find'' occurrences changed to ''replace''. {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , changestr(''find'', ''string'', ''replace'') ,
Rexx Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
, - , std.string.replace(''string'', ''find'', ''replace'') , D , - , Replace(''string'', ''find'', ''replace'') , VB , - , replace(''string'', ''find'', ''replace'') ,
Seed7 Seed7 is an extensible general-purpose programming language designed by Thomas Mertes. It is syntactically similar to Pascal and Ada. Along with many other features, it provides an extension mechanism. Daniel Zingaro"Modern Extensible Languages" ...
, - , change(''string'', ''find'', ''replace'') ,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , ''string''.Replace(''find'', ''replace'') , C#, F#, VB .NET , - , str_replace(''find'', ''replace'', ''string'') ,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , re:replace(''string'', ''find'', ''replace'', «{return, list}») , Erlang , - , ''string''.replace(''find'', ''replace'') , Cobra,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
(1.5+),
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
, - , ''string''.replaceAll(''find_regex'', ''replace'') ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, - , ''string''.gsub(''find'', ''replace'') ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, - , ''string'' =~ s/''find_regex''/''replace''/gThe "find" string in this construct is interpreted as a
regular expression A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or ...
. Certain characters have special meaning in regular expressions. If you want to find a string literally, you need to quote the special characters.
,
Perl 5 Perl is a family of two High-level programming language, high-level, General-purpose programming language, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it ...
, - , ''string''.subst(''find'', ''replace'', :g) , Raku , - , ''string''.replace(''find'', ''replace'', "g") or
''string''.replace(/''find_regex''/g, ''replace'')
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - ,
echo In audio signal processing and acoustics, an echo is a reflection of sound that arrives at the listener with a delay after the direct sound. The delay is directly proportional to the distance of the reflecting surface from the source and the list ...
"''string''" ,
sed sed ("stream editor") is a Unix utility that parses and transforms text, using a simple, compact programming language. It was developed from 1973 to 1974 by Lee E. McMahon of Bell Labs, and is available today for most operating systems. sed w ...
's/''find_regex''/''replace''/g'
,
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
, - , ${''string_param''//''find_pattern''/''replace''} ,
Bash Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
, - , ''string''.replace(''find'', ''replace''), or
''string'' -replace ''find_regex'', ''replace''
,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, - , Str.global_replace (Str.regexp_string ''find'') ''replace'' ''string'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, - , 'string'' stringByReplacingOccurrencesOfString:''find'' withString:''replace''/code> ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only) , - , ''string''.stringByReplacingOccurrencesOfString(''find'', withString:''replace'') ,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(Foundation) , - , string.gsub(''string'', ''find'', ''replace'')
(''string''):gsub(''find'', ''replace'')
,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , ''string'' copyReplaceAll: ''find'' with: ''replace'' ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
(
Squeak Squeak is an object-oriented, class-based, and reflective programming language. It was derived from Smalltalk-80 by a group that included some of Smalltalk-80's original developers, initially at Apple Computer, then at Walt Disney Imagineering, ...
,
Pharo Pharo is an open source, cross-platform implementation of the classic Smalltalk-80 programming language and runtime. It's based on the OpenSmalltalk virtual machine called Cog (VM), which evaluates a dynamic, reflective, and object-orient ...
) , - , string map {''find'' ''replace''} ''string'' ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, - , StringReplace 'string'', ''find'' -> ''replace''/code> ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
, - , strings.Replace(''string'', ''find'', ''replace'', -1) , Go , - , INSPECT ''string'' REPLACING ALL/LEADING/FIRST ''find'' BY ''replace'' ,
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, - , ''find_regex'' ⎕R ''replace_regex'' ⊢ ''string'' , APL // Examples in C# "effffff".Replace("f", "jump"); // returns "ejumpjumpjumpjumpjumpjump" "blah".Replace("z", "y"); // returns "blah" // Examples in Java "effffff".replace("f", "jump"); // returns "ejumpjumpjumpjumpjumpjump" "effffff".replaceAll("f*", "jump"); // returns "ejump" // Examples in Raku "effffff".subst("f", "jump", :g); # returns "ejumpjumpjumpjumpjumpjump" "blah".subst("z", "y", :g); # returns "blah" ' Examples in Visual Basic Replace("effffff", "f", "jump") ' returns "ejumpjumpjumpjumpjumpjump" Replace("blah", "z", "y") ' returns "blah" # Examples in Windows PowerShell "effffff" -replace "f", "jump" # returns "ejumpjumpjumpjumpjumpjump" "effffff" -replace "f*", "jump" # returns "ejump"


reverse

{, class="wikitable" , - style="background:#fffeed;" ! Definition , reverse(''string'') , - ! Description , Reverses the order of the characters in the string. {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , reverse ''string'' ,
Perl 5 Perl is a family of two High-level programming language, high-level, General-purpose programming language, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it ...
,
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
, - , flip ''string''
''string''.flip , Raku , - , lists:reverse(''string'') , Erlang , - , strrev(''string'') ,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , ''string'' :-1/code> ,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, - , (string-reverse ''string'') ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
(SRFI 13) , - , (reverse ''string'') ,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, - , ''string''.reverse ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, D (modifies string) , - , new StringBuilder(''string'').reverse().toString() ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, - , std::reverse(''string''.begin(), ''string''.end()); ,
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
( std::string only, modifies string) , - , StrReverse(''string'') , VB , - , ''string''.Reverse() , VB .NET, C# , - , implode (rev (explode ''string'')) ,
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of the ...
, - , ''string''.split("").reverse().join("") ,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , string.reverse(''string'')
(''string''):reverse()
,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , ''string'' reverse ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
, - , StringReverse 'string''/code> ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
, - , reverse(''string'') ,
PL/I PL/I (Programming Language One, pronounced and sometimes written PL/1) is a procedural, imperative computer programming language developed and published by IBM. It is designed for scientific, engineering, business and system programming. I ...
, - , «FUNCTION» REVERSE(''string'') ,
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, - , ''string''.toCharArray.toList.reversed.join() , Cobra , - , String(''string''.characters.reverse()) ,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(2.x) , - , String(reverse(''string'')) ,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(1.2) , - , string reverse ''string'' ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, - , ⌽''string'' , APL , - , ''string''.chars().rev().collect::() ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
, - , echo ''string'' , rev ,
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
" Example in Smalltalk " 'hello' reversed " returns 'olleh' " # Example in Perl 5 reverse "hello" # returns "olleh" # Example in Raku "hello".flip # returns "olleh" # Example in Python "hello" :-1 # returns "olleh" ; Example in Scheme (use-modules (srfi srfi-13)) (string-reverse "hello") ; returns "olleh"


rfind

{, class="wikitable" , - style="background:#fffeed;" ! Definition , rfind(''string'',''substring'') returns integer , - ! Description , Returns the position of the start of the last 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 , instr {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages !! If not found , - , InStrRev(«''startpos'',» ''string'',''substring'') , VB , returns 0 , - , instrrev(«''startpos'',» ''string'',''substring'') ,
FreeBASIC FreeBASIC is a free and open source multiplatform compiler and programming language based on BASIC licensed under the GNU GPL for Microsoft Windows, protected-mode MS-DOS (DOS extender), Linux, FreeBSD and Xbox. The Xbox version is no longer m ...
, returns 0 , - , rindex(''string'',''substring''«,''startpos''») ,
Perl 5 Perl is a family of two High-level programming language, high-level, General-purpose programming language, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it ...
, returns −1 , - , rindex(''string'',''substring''«,''startpos''»)
''string''.rindex(''substring''«,''startpos''») , Raku , returns Nil , - , strrpos(''string'',''substring''«,''startpos''») ,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, returns FALSE , - , ''string''.rfind(''substring''«,''startpos''») ,
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
(STL) , returns std::string::npos , - , std.string.rfind(''string'', ''substring'') , D , returns −1 , - , ''string''.rfind(''substring''«,''startpos''«, ''endpos''»») , rowspan=2,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, returns −1 , - , ''string''.rindex(''substring''«,''startpos''«, ''endpos''»») , raises ValueError , - , rpos(''string'', ''substring''«,''startpos''») ,
Seed7 Seed7 is an extensible general-purpose programming language designed by Thomas Mertes. It is syntactically similar to Pascal and Ada. Along with many other features, it provides an extension mechanism. Daniel Zingaro"Modern Extensible Languages" ...
, returns 0 , - , ''string''.rindex(''substring''«,''startpos''») ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, returns nil , - , strings.LastIndex(''string'', ''substring'') , Go , returns −1 , - , ''string''.lastIndexOf(''substring''«,''startpos''») ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, returns −1 , - , ''string''.LastIndexOf(''substring''«,''startpos''«, ''charcount''»») , VB .NET, C#,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, F# , returns −1 , - , (search ''substring'' ''string'' :from-end t) ,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, returns NIL , - , 'string'' rangeOfString:''substring'' options:NSBackwardsSearchlocation ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only) , returns NSNotFound , - , Str.search_backward (Str.regexp_string ''substring'') ''string'' (Str.length ''string'' - 1) ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, raises Not_found , - , string.match(''string'', '.*()'..''substring'')
''string'':match('.*()'..''substring'')
,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, returns nil , - , Ada.Strings.Unbounded.Index(Source => ''string'', Pattern => ''substring'',
Going => Ada.Strings.Backward)
,
Ada Ada may refer to: Places Africa * Ada Foah, a town in Ghana * Ada (Ghana parliament constituency) * Ada, Osun, a town in Nigeria Asia * Ada, Urmia, a village in West Azerbaijan Province, Iran * Ada, Karaman, a village in Karaman Province, ...
, returns 0 , - , ''string''.lastIndexOf(''substring''«,''startpos''«, ''charcount''»») , Cobra , returns −1 , - , ''string'' lastIndexOfString:''substring'' ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
, returns 0 , - , string last ''substring string startpos'' ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, returns −1 , - , (⌽<\⌽''substring''⍷'string')⍳1 , APL , returns −1 , - , ''string''.rfind(''substring'') ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
, returns None ; Examples in Common Lisp (search "e" "Hello mate" :from-end t) ; returns 9 (search "z" "word" :from-end t) ; returns NIL // Examples in C# "Hello mate".LastIndexOf("e"); // returns 9 "Hello mate".LastIndexOf("e", 4); // returns 1 "word".LastIndexOf("z"); // returns -1 # Examples in Perl 5 rindex("Hello mate", "e"); # returns 9 rindex("Hello mate", "e", 4); # returns 1 rindex("word", "z"); # returns -1 # Examples in Raku "Hello mate".rindex("e"); # returns 9 "Hello mate".rindex("e", 4); # returns 1 "word".rindex('z'); # returns Nil ' Examples in Visual Basic InStrRev("Hello mate", "e") ' returns 10 InStrRev(5, "Hello mate", "e") ' returns 2 InStrRev("word", "z") ' returns 0


right

{, class="wikitable" , - style="background:#fffeed;" ! Definition , right(''string'',''n'') returns string , - ! Description , Returns the right ''n'' part of a string. If ''n'' is greater than the length of the string then most implementations return the whole string (exceptions exist – see code examples). {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , string (string'Last - ''n'' + 1 .. string'Last) ,
Ada Ada may refer to: Places Africa * Ada Foah, a town in Ghana * Ada (Ghana parliament constituency) * Ada, Osun, a town in Nigeria Asia * Ada, Urmia, a village in West Azerbaijan Province, Iran * Ada, Karaman, a village in Karaman Province, ...
, - , Right(''string'',''n'') , VB , - , RIGHT$(''string'',''n'') ,
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
, - , right(''string'',''n'') ,
FreeBASIC FreeBASIC is a free and open source multiplatform compiler and programming language based on BASIC licensed under the GNU GPL for Microsoft Windows, protected-mode MS-DOS (DOS extender), Linux, FreeBSD and Xbox. The Xbox version is no longer m ...
, Ingres,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , strcpy(''string2'', ''string''+''n'') (n must not be greater than the length of ''string'') , C , - , ''string''.Substring(''string''.Length()-''n'') , C# , - , ''string'' en(''string'')-''n'':/code> , Go , - , ''string''.substring(''string''.length()-''n'') ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, - , ''string''.slice(-''n'') ,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , right(''string'',''n'' «,''padchar''») ,
Rexx Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
, Erlang , - , substr(''string'',-''n'') ,
Perl 5 Perl is a family of two High-level programming language, high-level, General-purpose programming language, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it ...
,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , substr(''string'',*-''n'')
''string''.substr(*-''n'') , Raku , - , ''string'' ''n'':/code> , Cobra,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, - , ${''string_param'': -''n''} (note the space after the colon) ,
Bash Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
, - , ''string'' 'n''/code> ,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , (string-take-right ''string'' ''n'') ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
(SRFI 13) , - , ''string'' ''n''..-1/code> ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, - , ''string'' -''n'' .. $/code> , D , - , String.sub ''string'' (String.length ''string'' - ''n'') ''n'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, - , string.sub(''string'', -''n'')
(''string''):sub(-''n'')
,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , ''string'' last: ''n'' ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
(
Squeak Squeak is an object-oriented, class-based, and reflective programming language. It was derived from Smalltalk-80 by a group that included some of Smalltalk-80's original developers, initially at Apple Computer, then at Walt Disney Imagineering, ...
,
Pharo Pharo is an open source, cross-platform implementation of the classic Smalltalk-80 programming language and runtime. It's based on the OpenSmalltalk virtual machine called Cog (VM), which evaluates a dynamic, reflective, and object-orient ...
) , - , StringTake 'string'', -''n''/code> ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
, - , ''string'' (1:''n'') ,
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, - , ''¯n''↑''string''. , APL , - , ''string'' ../code>
''string''.get(n..) ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
// Examples in Java; extract rightmost 4 characters String str = "CarDoor"; str.substring(str.length()-4); // returns 'Door' # Examples in Raku "abcde".substr(*-3); # returns "cde" "abcde".substr(*-8); # 'out of range' error /* Examples in Rexx */ right("abcde", 3) /* returns "cde" */ right("abcde", 8) /* returns " abcde" */ right("abcde", 8, "*") /* returns "***abcde" */ ; Examples in Scheme (use-modules (srfi srfi-13)) (string-take-right "abcde", 3) ; returns "cde" (string-take-right "abcde", 8) ; error ' Examples in Visual Basic Right("sandroguidi", 3) ' returns "idi" Right("sandroguidi", 100) ' returns "sandroguidi"


rpartition

{, class="wikitable" , - style="background:#fffeed;" ! Definition , .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 , - , ''string''.rpartition(''separator'') ,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
# Examples in Python "Spam eggs spam spam and ham".rpartition('spam') ### ('Spam eggs spam ', 'spam', ' and ham') "Spam eggs spam spam and ham".rpartition('X') ### ("", "", 'Spam eggs spam spam and ham')


slice

''see'' #substring


split

{, class="wikitable" , - style="background:#fffeed;" ! Definition , .split(''separator'' ''limit'' splits a string on separator, optionally only up to a limited number of substrings , - ! Description , Splits the given string by occurrences of the separator (itself a string) and returns a list (or array) of the substrings. If ''limit'' is given, after ''limit'' – 1 separators have been read, the rest of the string is made into the last substring, regardless of whether it has any separators in it. The Scheme and Erlang implementations are similar but differ in several ways. JavaScript differs also in that it cuts, it does not put the rest of the string into the last element
See the example here
The Cobra implementation will default to whitespace. Opposite of ''join''. {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , split(/''separator''/, ''string''«, ''limit''») ,
Perl 5 Perl is a family of two High-level programming language, high-level, General-purpose programming language, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it ...
, - , split(''separator'', ''string''«, ''limit''»)
''string''.split(''separator'', «''limit''») , Raku , - , explode(''separator'', ''string''«, ''limit''») ,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , ''string''.split(''separator''«, ''limit''-1») ,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, - , ''string''.split(''separator''«, ''limit''») ,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, - , string:tokens(''string'', ''sepchars'') , Erlang , - , strings.Split(''string'', ''separator'')
strings.SplitN(''string'', ''separator'', ''limit'')
, Go , - , (string-tokenize ''string''« ''charset''« ''start''« ''end''»»») ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
(SRFI 13) , - , Split(''string'', ''sepchars''«, ''limit''») , VB , - , ''string''.Split(''sepchars''«, ''limit''«, ''options''»») , VB .NET, C#, F# , - , ''string'' -split ''separator''«, ''limit''«, ''options''»» ,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, - , Str.split (Str.regexp_string ''separator'') ''string'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, - , std.string.split(''string'', ''separator'') , D , - , 'string'' componentsSeparatedByString:''separator''/code> ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only) , - , ''string''.componentsSeparatedByString(''separator'') ,
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(Foundation) , - , TStringList.Delimiter, TStringList.DelimitedText ,
Object Pascal Object Pascal is an extension to the programming language Pascal (programming language), Pascal that provides object-oriented programming (OOP) features such as Class (computer programming), classes and Method (computer programming), methods. ...
, - , StringSplit 'string'', ''separator''«, ''limit''»/code> ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
, - , ''string''.split«(''sepchars''«, ''limit''«, ''options''»»)» , Cobra , - , split ''string separator'' ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, - , (''separator''≠''string'')⊂''string'' or ''separator''(≠⊆⊢)''string'' in APL2 and Dyalog APL 16.0 respectively , APL , - , ''string''.split(''separator'') ''string''.split(''limit'', ''separator'') ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
// Example in C# "abc,defgh,ijk".Split(','); // {"abc", "defgh", "ijk"} "abc,defgh;ijk".Split(',', ';'); // {"abc", "defgh", "ijk"} % Example in Erlang string:tokens("abc;defgh;ijk", ";"). % abc", "defgh", "ijk" // Examples in Java "abc,defgh,ijk".split(","); // {"abc", "defgh", "ijk"} "abc,defgh;ijk".split(",, ;"); // {"abc", "defgh", "ijk"} { Example in Pascal } var lStrings: TStringList; lStr: string; begin lStrings := TStringList.Create; lStrings.Delimiter := ','; lStrings.DelimitedText := 'abc,defgh,ijk'; lStr := lStrings.Strings // 'abc' lStr := lStrings.Strings // 'defgh' lStr := lStrings.Strings // 'ijk' end; # Examples in Perl 5 split(/spam/, 'Spam eggs spam spam and ham'); # ('Spam eggs ', ' ', ' and ham') split(/X/, 'Spam eggs spam spam and ham'); # ('Spam eggs spam spam and ham') # Examples in Raku 'Spam eggs spam spam and ham'.split(/spam/); # (Spam eggs and ham) split(/X/, 'Spam eggs spam spam and ham'); # (Spam eggs spam spam and ham)


sprintf

''see'' #Format


strip

''see'' #trim


strcmp

''see'' #Compare (integer result)


substring

{, class="wikitable" , - style="background:#fffeed;" ! Definition , substring(''string'', ''startpos'', ''endpos'') returns string
substr(''string'', ''startpos'', ''numChars'') 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-8 is a variable-width encoding, variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit'' ...
,
UTF-16 UTF-16 (16-bit computing, 16-bit Unicode Transformation Format) is a character encoding capable of encoding all 1,112,064 valid code points of Unicode (in fact this number of code points is dictated by the design of UTF-16). The encoding is variab ...
or Shift-JIS, it can be necessary to remove string positions at the end, in order to avoid invalid strings. {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , string 'startpos'':''endpos''/code> ,
ALGOL 68 ALGOL 68 (short for ''Algorithmic Language 1968'') is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously de ...
(changes base index) , - , string (''startpos'' .. ''endpos'') ,
Ada Ada may refer to: Places Africa * Ada Foah, a town in Ghana * Ada (Ghana parliament constituency) * Ada, Osun, a town in Nigeria Asia * Ada, Urmia, a village in West Azerbaijan Province, Iran * Ada, Karaman, a village in Karaman Province, ...
(changes base index) , - , Mid(''string'', ''startpos'', ''numChars'') , VB , - , mid(''string'', ''startpos'', ''numChars'') ,
FreeBASIC FreeBASIC is a free and open source multiplatform compiler and programming language based on BASIC licensed under the GNU GPL for Microsoft Windows, protected-mode MS-DOS (DOS extender), Linux, FreeBSD and Xbox. The Xbox version is no longer m ...
, - , ''string'' 'startpos''+(⍳''numChars'')-~⎕IO/code> , APL , - , MID$(''string'', ''startpos'', ''numChars'') ,
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
, - , substr(''string'', ''startpos'', ''numChars'') ,
AWK AWK (''awk'') is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems. The AWK lang ...
(changes string),
Perl 5 Perl is a family of two High-level programming language, high-level, General-purpose programming language, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it ...
,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , substr(''string'', ''startpos'', ''numChars'')
''string''.substr(''startpos'', ''numChars'') , Raku , - , substr(''string'', ''startpos'' «,''numChars'', ''padChar''») ,
Rexx Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
, - , ''string'' 'startpos'':''endpos''/code> , Cobra,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, Go , - , ''string'' 'startpos'', ''numChars''/code> ,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , ''string'' 'startpos'', ''numChars''
''string'' 'startpos'' .. ''endpos''-1
''string'' 'startpos'' ... ''endpos''/code> ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, - , ''string'' 'startpos'' .. ''endpos''
''string'' 'startpos'' len ''numChars''/code> ,
Seed7 Seed7 is an extensible general-purpose programming language designed by Thomas Mertes. It is syntactically similar to Pascal and Ada. Along with many other features, it provides an extension mechanism. Daniel Zingaro"Modern Extensible Languages" ...
, - , ''string''.slice(''startpos''«, ''endpos''») ,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , ''string''.substr(''startpos''«, ''numChars''») ,
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
(STL),
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , ''string''.Substring(''startpos'', ''numChars'') , VB .NET, C#,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, F# , - , ''string''.substring(''startpos''«, ''endpos''») ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , copy(''string'', ''startpos'', ''numChars'') ,
Object Pascal Object Pascal is an extension to the programming language Pascal (programming language), Pascal that provides object-oriented programming (OOP) features such as Class (computer programming), classes and Method (computer programming), methods. ...
(
Delphi Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracle ...
) , - , (substring ''string'' ''startpos'' ''endpos'') ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
, - , (subseq ''string'' ''startpos'' ''endpos'') ,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, - , (subseq ''string'' ''startpos'' ''endpos'') ,
ISLISP ISLISP (also capitalized as ISLisp) is a programming language in the Lisp family standardized by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC) joint working group ISO/IEC JTC 1/SC 22/W ...
, - , String.sub ''string'' ''startpos'' ''numChars'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, - , substring (''string'', ''startpos'', ''numChars'') ,
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of the ...
, - , string:sub_string(''string'', ''startpos'', ''endpos'')
string:substr(''string'', ''startpos'', ''numChars'')
, Erlang , - , strncpy(''result'', ''string'' + ''startpos'', ''numChars''); , C , - , ''string'' 'startpos'' .. ''endpos''+1/code> , D , - , take ''numChars'' $ drop ''startpos'' ''string'' ,
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
, - , 'string'' substringWithRange:NSMakeRange(''startpos'', ''numChars'')/code> ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only) , - , ''string''. 'startpos''..''endpos''/code> , F# , - , string.sub(''string'', ''startpos'', ''endpos'')
(''string''):sub(''startpos'', ''endpos'')
,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , ''string'' copyFrom: ''startpos'' to: ''endpos'' ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
, - , ''string''(''startpos'':''endpos'') , Fortran , - , SUBSTRING(''string'' FROM ''startpos'' «FOR ''numChars''») , SQL , - , StringTake 'string'', {''startpos'', ''endpos''}/code> ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
, - , ''string'' (''startpos'':''numChars'') ,
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, - , ${''string_param'':''startpos'':''numChars''} ,
Bash Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
, - , string range ''string startpos endpos'' ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, - , ''string'' 'startpos''..''endpos''/code>
''string''.get(''startpos''..''endpos'') ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
// Examples in C# "abc".Substring(1, 1): // returns "b" "abc".Substring(1, 2); // returns "bc" "abc".Substring(1, 6); // error ;; Examples in Common Lisp (subseq "abc" 1 2) ; returns "b" (subseq "abc" 2) ; returns "c" % Examples in Erlang string:substr("abc", 2, 1). % returns "b" string:substr("abc", 2). % returns "bc" # Examples in Perl 5 substr("abc", 1, 1); # returns "b" substr("abc", 1); # returns "bc" # Examples in Raku "abc".substr(1, 1); # returns "b" "abc".substr(1); # returns "bc" # Examples in Python "abc" :2 # returns "b" "abc" :3 # returns "bc" /* Examples in Rexx */ substr("abc", 2, 1) /* returns "b" */ substr("abc", 2) /* returns "bc" */ substr("abc", 2, 6) /* returns "bc " */ substr("abc", 2, 6, "*") /* returns "bc****" */


Uppercase

{, class="wikitable" , - style="background:#fffeed;" ! Definition , uppercase(''string'') returns string , - ! Description , Returns the string in upper case. {, class="wikitable sortable" , - style="text-align:left;" ! Format !! Languages , - , UCase(''string'') , VB , - , ucase(''string'') ,
FreeBASIC FreeBASIC is a free and open source multiplatform compiler and programming language based on BASIC licensed under the GNU GPL for Microsoft Windows, protected-mode MS-DOS (DOS extender), Linux, FreeBSD and Xbox. The Xbox version is no longer m ...
, - , toupper(''string'') ,
AWK AWK (''awk'') is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems. The AWK lang ...
(changes string) , - , uc(''string'') ,
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
, Raku , - , ''string''.uc , Raku , - , toupper(''char'') , C (operates on one character) , - , for(size_t i = 0, len = strlen(''string''); i< len; i++) ''string'' = toupper(''string'' ;
for (char *c = ''string''; *c != '\0'; c++) *c = toupper(*c); , C (string / char array) , - , std.string.toUpper(''string'') , D , - , transform(''string''.begin(), ''string''.end(), ''result''.begin(), toupper) ,
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
, - , uppercase(''string'') ,
Object Pascal Object Pascal is an extension to the programming language Pascal (programming language), Pascal that provides object-oriented programming (OOP) features such as Class (computer programming), classes and Method (computer programming), methods. ...
(
Delphi Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracle ...
) , - , upcase(''char'') ,
Object Pascal Object Pascal is an extension to the programming language Pascal (programming language), Pascal that provides object-oriented programming (OOP) features such as Class (computer programming), classes and Method (computer programming), methods. ...
(
Delphi Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracle ...
) (operates on one character) , - , strtoupper(''string'') ,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, - , upper(''string'') ,
Seed7 Seed7 is an extensible general-purpose programming language designed by Thomas Mertes. It is syntactically similar to Pascal and Ada. Along with many other features, it provides an extension mechanism. Daniel Zingaro"Modern Extensible Languages" ...
, - , ${''string_param''^^} (mnemonic: ^ is pointing up) ,
Bash Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
, - ,
echo In audio signal processing and acoustics, an echo is a reflection of sound that arrives at the listener with a delay after the direct sound. The delay is directly proportional to the distance of the reflecting surface from the source and the list ...
"string" , tr 'a-z' 'A-Z'
,
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
, - , translate(''string''), or
UPPER variables, or
PARSE UPPER VAR SrcVar DstVar ,
Rexx Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
, - , ''string''.upper() ,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, - , upcase(''string'') ,
Pick Basic The Pick Operating System (Pick System or Pick) is a demand-paged, multi-user, virtual memory, time-sharing computer operating system based around a MultiValue database. Pick is used primarily for business data processing. It is named after one ...
, - , ''string''.upcase ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, - , strings.ToUpper(''string'') , Go , - , (string-upcase ''string'') ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, - , String.uppercase ''string'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, - , String.map Char.toUpper ''string'' ,
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of the ...
, - , map Char.toUpper ''string'' ,
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
, - , ''string''.toUpperCase() ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, - , to_upper(''string'') , Erlang , - , ''string''.ToUpper() , VB .NET, C#,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, F# , - , ''string''.uppercaseString ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
(NSString * only),
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
(Foundation) , - , string.upper(''string'')
(''string''):upper()
,
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
, - , ''string'' asUppercase ,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
, - , UPPER(''string'') , SQL , - , ToUpperCase 'string''/code> ,
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
, - , «FUNCTION» UPPER-CASE(''string'') ,
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, - , ''string''.toUpper , Cobra , - , string toupper ''string'' ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, - , ''string''.to_uppercase() ,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
// Example in C# "Wiki means fast?".ToUpper(); // "WIKI MEANS FAST?" # Example in Perl 5 uc("Wiki means fast?"); # "WIKI MEANS FAST?" # Example in Raku uc("Wiki means fast?"); # "WIKI MEANS FAST?" "Wiki means fast?".uc; # "WIKI MEANS FAST?" /* Example in Rexx */ translate("Wiki means fast?") /* "WIKI MEANS FAST?" */ /* Example #2 */ A='This is an example.' UPPER A /* "THIS IS AN EXAMPLE." */ /* Example #3 */ A='upper using Translate Function.' Translate UPPER VAR A Z /* Z="UPPER USING TRANSLATE FUNCTION." */ ; Example in Scheme (use-modules (srfi srfi-13)) (string-upcase "Wiki means fast?") ; "WIKI MEANS FAST?" ' Example in Visual Basic UCase("Wiki means fast?") ' "WIKI MEANS FAST?"


trim

trim or strip is used to remove whitespace from the beginning, end, or both beginning and end, of a string. {, class="wikitable" , - style="text-align:left;" ! Example usage !! Languages , - , ''String''.Trim( 'chars'' , C#,
VB.NET Visual Basic, originally called Visual Basic .NET (VB.NET), is a multi-paradigm, object-oriented programming language, implemented on .NET, Mono, and the .NET Framework. Microsoft launched VB.NET in 2002 as the successor to its original Visua ...
,
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, - , ''string''.strip(); , D , - , (.trim ''string'') ,
Clojure Clojure (, like ''closure'') is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system. The current development process is comm ...
, - , ''sequence'' predicate? trim ,
Factor Factor, a Latin word meaning "who/which acts", may refer to: Commerce * Factor (agent), a person who acts for, notably a mercantile and colonial agent * Factor (Scotland), a person or firm managing a Scottish estate * Factors of production, suc ...
, - , (string-trim '(#\Space #\Tab #\Newline) ''string'') ,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, - , (string-trim ''string'') ,
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
, - , ''string''.trim() ,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
(1.8.1+, Firefox 3.5+),
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
, - , Trim(''String'') ,
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, Fren ...
,
QBasic QBasic is an integrated development environment (IDE) and interpreter for a variety of dialects of BASIC which are based on QuickBASIC. Code entered into the IDE is compiled to an intermediate representation (IR), and this IR is immediately e ...
,
Visual Basic Visual Basic is a name for a family of programming languages from Microsoft. It may refer to: * Visual Basic .NET (now simply referred to as "Visual Basic"), the current version of Visual Basic launched in 2002 which runs on .NET * Visual Basic (cl ...
,
Delphi Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracle ...
, - , ''string''.strip() ,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
, - , strings.Trim(''string'', ''chars'') , Go , - , LTRIM(RTRIM(''String'')) ,
Oracle An oracle is a person or agency considered to provide wise and insightful counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. As such, it is a form of divination. Description The word '' ...
SQL,
T-SQL Transact-SQL (T-SQL) is Microsoft's and Sybase's proprietary extension to the SQL (Structured Query Language) used to interact with relational databases. T-SQL expands on the SQL standard to include procedural programming, local variables, var ...
, - , strip(''string'' ''option'', ''char'' ,
REXX Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
, - , string:strip(''string'' ''option'', ''char'' , Erlang , - , ''string''.strip or ''string''.lstrip or ''string''.rstrip ,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, - , ''string''.trim , Raku , - , trim(''string'') ,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, Raku , - , 'string'' stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ,
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
using Cocoa (API), Cocoa , - , ''string'' withBlanksTrimmed
''string'' withoutSpaces
''string'' withoutSeparators
,
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
(Squeak, Pharo)
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
, - , strip(string) , SAS , - , string trim ''$string'' ,
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, - , TRIM(''string'') or TRIM(ADJUSTL(''string'')) , Fortran , - , TRIM(''string'') , SQL , - , TRIM(''string'') or LTrim(''string'') or RTrim(''String'') ,
ColdFusion Adobe ColdFusion is a commercial rapid web-application development computing platform created by J. J. Allaire in 1995. (The programming language used with that platform is also commonly called ColdFusion, though is more accurately known as CF ...
, - , String.trim ''string'' ,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
4+ Other languages In languages without a built-in trim function, it is usually simple to create a custom function which accomplishes the same task.


APL

APL can use regular expressions directly: Trim←'^ +, +$'⎕R'' Alternatively, a functional approach combining Boolean masks that filter away leading and trailing spaces: Trim←{⍵/⍨(∨\∧∘⌽∨\∘⌽)' '≠⍵} Or reverse and remove leading spaces, twice: Trim←{(∨\' '≠⍵)/⍵}∘⌽⍣2


AWK

In
AWK AWK (''awk'') is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems. The AWK lang ...
, one can use regular expressions to trim: ltrim(v) = gsub(/^ \t/, "", v) rtrim(v) = gsub(/ \t$/, "", v) trim(v) = ltrim(v); rtrim(v) or: function ltrim(s) { sub(/^ \t/, "", s); return s } function rtrim(s) { sub(/ \t$/, "", s); return s } function trim(s) { return rtrim(ltrim(s)); }


C/C++

There is no standard trim function in C or C++. Most of the available string libraries for C contain code which implements trimming, or functions that significantly ease an efficient implementation. The function has also often been called EatWhitespace in some non-standard C libraries. In C, programmers often combine a ltrim and rtrim to implement trim: #include #include void rtrim(char *str) { char *s; s = str + strlen(str); while (--s >= str) { if (!isspace(*s)) break; *s = 0; } } void ltrim(char *str) { size_t n; n = 0; while (str != '\0' && isspace((unsigned char) str ) { n++; } memmove(str, str + n, strlen(str) - n + 1); } void trim(char *str) { rtrim(str); ltrim(str); } The
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
C++ library Boost has several trim variants, including a standard one: #include trimmed = boost::algorithm::trim_copy("string"); Note that with boost's function named simply trim the input sequence is modified in-place, and does not return a result. Another
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
C++ library Qt has several trim variants, including a standard one: #include trimmed = s.trimmed(); The
Linux kernel The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
also includes a strip function, strstrip(), since 2.6.18-rc1, which trims the string "in place". Since 2.6.33-rc1, the kernel uses strim() instead of strstrip() to avoid false warnings.


Haskell

A trim algorithm in
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
: import Data.Char (isSpace) trim :: String -> String trim = f . f where f = reverse . dropWhile isSpace may be interpreted as follows: ''f'' drops the preceding whitespace, and reverses the string. ''f'' is then again applied to its own output. Note that the type signature (the second line) is optional.


J

The trim algorithm in J is a
functional Functional may refer to: * Movements in architecture: ** Functionalism (architecture) ** Form follows function * Functional group, combination of atoms within molecules * Medical conditions without currently visible organic basis: ** Functional sy ...
description: trim =. #~ [: (+./\ *. +./\.) ' '&~: That is: filter (#~) for non-space characters (' '&~:) between leading (+./\) and (*.) trailing (+./\.) spaces.


JavaScript

There is a built-in trim function in JavaScript 1.8.1 (Firefox 3.5 and later), and the ECMAScript 5 standard. In earlier versions it can be added to the String object's prototype as follows: String.prototype.trim = function() { return this.replace(/^\s+/g, "").replace(/\s+$/g, ""); };


Perl

Perl 5 has no built-in trim function. However, the functionality is commonly achieved using
regular expression A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or ...
s. Example: $string =~ s/^\s+//; # remove leading whitespace $string =~ s/\s+$//; # remove trailing whitespace or: $string =~ s/^\s+, \s+$//g ; # remove both leading and trailing whitespace These examples modify the value of the original variable $string. Also available for Perl is StripLTSpace in String::Strip from CPAN. There are, however, two functions that are commonly used to strip whitespace from the end of strings, chomp and chop: * chop
/code> removes the last character from a string and returns it. *
/code> removes the trailing newline character(s) from a string if present. (What constitutes a newline i

dependent). In Raku, the upcoming sister language of Perl, strings have a trim method. Example: $string = $string.trim; # remove leading and trailing whitespace $string .= trim; # same thing


Tcl

The
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company **TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
string command has three relevant subcommands: trim, trimright and trimleft. For each of those commands, an additional argument may be specified: a string that represents a set of characters to remove—the default is whitespace (space, tab, newline, carriage return). Example of trimming vowels: set string onomatopoeia set trimmed
tring trim $string aeiou Tring is a market town and civil parishes in England, civil parish in the Borough of Dacorum, Hertfordshire, England. It is situated in a gap passing through the Chiltern Hills, classed as an Area of Outstanding Natural Beauty, from Central ...
;# result is nomatop set r_trimmed tring trimright $string aeiou ;# result is onomatop set l_trimmed tring trimleft $string aeiou ;# result is nomatopoeia


XSLT

XSLT XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subseque ...
includes the function normalize-space(''string'') which strips leading and trailing whitespace, in addition to replacing any whitespace sequence (including line breaks) with a single space. Example: XSLT 2.0 includes regular expressions, providing another mechanism to perform string trimming. Another XSLT technique for trimming is to utilize the XPath 2.0 substring() function.


References

{{Reflist, refs= the index can be negative, which then indicates the number of places before the end of the string. the index can not be negative, use *-N where N indicate the number of places before the end of the string. ''startpos'' can be negative, which indicates to start that number of places before the end of the string. ''endpos'' can be negative, which indicates to end that number of places before the end of the string. ''numChars'' can be negative, which indicates to end that number of places before the end of the string. ''startpos'' can not be negative, use ''* - startpos'' to indicate to start that number of places before the end of the string. ''numChars'' can not be negative, use ''* - numChars'' to indicate to end that number of places before the end of the string. *String functions Programming language comparison Articles with example Python (programming language) code