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 and regular expressions are handled in separate pages. Statements in guillemets (« … ») are optional.
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".
^a 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.
Tests if two strings are not equal. See also #Equality.
See CharAt for base of startpos/endpos.
trim or strip is used to remove whitespace from the beginning, end, or both beginning and end, of a string.
In languages without a built-in trim function, it is usually simple to create a custom function which accomplishes the same task.
Alternatively, a functional approach combining Boolean masks that filter away leading and trailing spaces:
Trim←{⍵/⍨(∨\∧∘⌽∨\∘⌽)' '≠⍵}
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.
With boost's function named simply trim the input sequence is modified in-place, and returns no result.
That is: filter (#~) for non-space characters (' '&~:) between leading (+./\) and (*.) trailing (+./\.) spaces.
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 5 has no built-in trim function. However, the functionality is commonly achieved using regular expressions.
These examples modify the value of the original variable $string.
There are, however, two functions that are commonly used to strip whitespace from the end of strings, chomp and chop:
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.
the index can be negative, which then indicates the number of places before the end of the string.
the index can be negative, which then indicates the number of places before the end of the string.
In Rust, the str::chars method iterates over code points and the std::iter::Iterator::nth method on iterators returns the zero-indexed nth value from the iterator, or None. https://doc.rust-lang.org/std/primitive.str.html#method.chars
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.
the index can be negative, which then indicates the number of places before the end of the string.
the index can be negative, which then indicates the number of places before the end of the string.
In C++, the overloaded operator<=> method on a string returns a std::strong_ordering object (otherwise std::weak_ordering): less, equal (same as equivalent), or greater. https://en.cppreference.com/w/cpp/language/operator_comparison#Three-way%20comparison
returns LESS, EQUAL, or GREATER
returns LT, EQ, or GT
returns .TRUE. or .FALSE.. These functions are based on the ASCII collating sequence.
IBM extension.
In Rust, the Ord::cmp method on a string returns an Ordering: Less, Equal, or Greater. https://doc.rust-lang.org/std/cmp/trait.Ord.html#tymethod.cmp
In Rust, the operators == and != and the methods eq, ne are implemented by the PartialEq trait, and the operators <, >, <=, >= and the methods lt, gt, le, ge are implemented by the PartialOrd trait. https://doc.rust-lang.org/std/primitive.str.html#impl-PartialEq%3Cstr%3E
The operators use the compiler's default collating sequence.
In Rust, the operators == and != and the methods eq, ne are implemented by the PartialEq trait, and the operators <, >, <=, >= and the methods lt, gt, le, ge are implemented by the PartialOrd trait. https://doc.rust-lang.org/std/primitive.str.html#impl-PartialEq%3Cstr%3E
modifies string1, which must have enough space to store the result
In Rust, the + operator is implemented by the Add trait. https://doc.rust-lang.org/stable/std/string/struct.String.html#impl-Add%3C%26%27_%20str%3E
See the str::contains method. https://doc.rust-lang.org/stable/std/primitive.str.html#method.contains
See the std::basic_string::contains method. https://en.cppreference.com/w/cpp/string/basic_string/contains
startpos is IBM extension.
In Rust, the operators == and != and the methods eq, ne are implemented by the PartialEq trait, and the operators <, >, <=, >= and the methods lt, gt, le, ge are implemented by the PartialOrd trait. https://doc.rust-lang.org/std/primitive.str.html#impl-PartialEq%3Cstr%3E
In Rust, the operators == and != and the methods eq, ne are implemented by the PartialEq trait, and the operators <, >, <=, >= and the methods lt, gt, le, ge are implemented by the PartialOrd trait. https://doc.rust-lang.org/std/primitive.str.html#impl-PartialEq%3Cstr%3E
startpos is IBM extension.
See the str::find method. https://doc.rust-lang.org/stable/std/primitive.str.html#method.find
startpos is IBM extension.
See the str::find method. https://doc.rust-lang.org/stable/std/primitive.str.html#method.find
"scan in Fortran Wiki". Fortranwiki.org. 2009-04-30. Retrieved 2013-08-18. http://fortranwiki.org/fortran/show/scan
"verify in Fortran Wiki". Fortranwiki.org. 2012-05-03. Retrieved 2013-08-18. http://fortranwiki.org/fortran/show/verify
formatstring must be a fixed literal at compile time for it to have the correct type.
See std::format, which is imported by the Rust prelude so that it can be used under the name format. https://doc.rust-lang.org/stable/std/macro.format.html
In Rust, the operators == and != and the methods eq, ne are implemented by the PartialEq trait, and the operators <, >, <=, >= and the methods lt, gt, le, ge are implemented by the PartialOrd trait. https://doc.rust-lang.org/std/primitive.str.html#impl-PartialEq%3Cstr%3E
In Rust, the operators == and != and the methods eq, ne are implemented by the PartialEq trait, and the operators <, >, <=, >= and the methods lt, gt, le, ge are implemented by the PartialOrd trait. https://doc.rust-lang.org/std/primitive.str.html#impl-PartialEq%3Cstr%3E
See the slice::join method. https://doc.rust-lang.org/stable/std/primitive.slice.html#method.join
if n is larger than the length of the string, then in Debug mode ArrayRangeException is thrown, in Release mode, the behaviour is unspecified. /wiki/Unspecified_behavior
if n is larger than the length of the string, Java will throw an IndexOutOfBoundsException
if n is larger than length of string, raises Invalid_argument
if n is larger than length of string, throw the message "StringTake::take:"
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. A &str (string reference) can be indexed by various types of ranges, including Range (0..n), RangeFrom (n..), and RangeTo (..n) because they all implement the SliceIndex trait with str being the type being indexed.
The str::get method is the non-panicking way to index. It returns None in the cases in which indexing would panic. /wiki/UTF-8
Ruby lacks Unicode support
See the str::len method. https://doc.rust-lang.org/stable/std/primitive.str.html#method.len
In Rust, the str::chars method iterates over code points and the std::iter::Iterator::count method on iterators consumes the iterator and returns the total number of elements in the iterator. https://doc.rust-lang.org/std/primitive.str.html#method.chars
operates on one character
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);
std::string only, result is stored in string result which is at least as long as string, and may or may not be string itself /wiki/Std::string
only ASCII characters as Ruby lacks Unicode support
IBM extension.
See the str::to_lowercase method. https://doc.rust-lang.org/stable/std/primitive.str.html#method.to_lowercase
See the str::replace method. https://doc.rust-lang.org/stable/std/primitive.str.html#method.replace
The "find" string in this construct is interpreted as a regular expression. Certain characters have special meaning in regular expressions. If you want to find a string literally, you need to quote the special characters. /wiki/Regular_expression
The "find" string in this construct is interpreted as a regular expression. Certain characters have special meaning in regular expressions. If you want to find a string literally, you need to quote the special characters. /wiki/Regular_expression
third parameter is non-standard
The "find" string in this construct is interpreted as a regular expression. Certain characters have special meaning in regular expressions. If you want to find a string literally, you need to quote the special characters. /wiki/Regular_expression
The "find" string in this construct is interpreted as a regular expression. Certain characters have special meaning in regular expressions. If you want to find a string literally, you need to quote the special characters. /wiki/Regular_expression
The "find" string in this construct is interpreted as a regular expression. Certain characters have special meaning in regular expressions. If you want to find a string literally, you need to quote the special characters. /wiki/Regular_expression
In Rust, the str::chars method iterates over code points, the std::iter::Iterator::rev method on reversible iterators (std::iter::DoubleEndedIterator) creates a reversed iterator, and the std::iter::Iterator::collect method consumes the iterator and creates a collection (which here is specified as a String with the turbofish syntax) from the iterator's elements. https://doc.rust-lang.org/std/primitive.str.html#method.chars
See the str::rfind method. https://doc.rust-lang.org/stable/std/primitive.str.html#method.rfind
"Annotated ES5". Es5.github.com. Archived from the original on 2013-01-28. Retrieved 2013-08-18. https://web.archive.org/web/20130128185825/https://es5.github.com/#x15.5.4.13
if n is larger than length of string, then in Debug mode ArrayRangeException is thrown, and unspecified behaviour in Release mode
if n is larger than length of string, raises Invalid_argument
if n is larger than length of string, throw the message "StringTake::take:"
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. A &str (string reference) can be indexed by various types of ranges, including Range (0..n), RangeFrom (n..), and RangeTo (..n) because they all implement the SliceIndex trait with str being the type being indexed.
The str::get method is the non-panicking way to index. It returns None in the cases in which indexing would panic. /wiki/UTF-8
See the str::split and str::rsplit methods. https://doc.rust-lang.org/stable/std/primitive.str.html#method.split
startpos can be negative, which indicates to start 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 be negative, which indicates to start 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.
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.
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.
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.
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.
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.
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. A &str (string reference) can be indexed by various types of ranges, including Range (0..n), RangeFrom (n..), and RangeTo (..n) because they all implement the SliceIndex trait with str being the type being indexed.
The str::get method is the non-panicking way to index. It returns None in the cases in which indexing would panic. /wiki/UTF-8
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);
std::string only, result is stored in string result which is at least as long as string, and may or may not be string itself /wiki/Std::string
only ASCII characters as Ruby lacks Unicode support
"uppercase - Kotlin Programming Language". Kotlin. Retrieved 9 November 2024. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/uppercase.html
In Rust, the str::to_uppercase method returns a newly allocated String with any lowercase characters changed to uppercase ones following the Unicode rules. https://doc.rust-lang.org/stable/std/primitive.str.html#method.to_uppercase
In Rust, the str::trim method returns a reference to the original &str. https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim
"Trim – GNU Pascal priručnik". Gnu-pascal.de. Retrieved 2013-08-24. http://gnu-pascal.de/gpc-hr/Trim.html
"String library comparison". And.org. Retrieved 2013-08-24. http://www.and.org/vstr/comparison
"Usage – 1.54.0". Boost.org. 2013-05-22. Retrieved 2013-08-24. http://www.boost.org/doc/html/string_algo/usage.html#id2742817
[1] Archived August 2, 2009, at the Wayback Machine http://doc.trolltech.com/4.5/qstring.html#trimmed
dankamongmen. "sprezzos-kernel-packaging/changelog at master · dankamongmen/sprezzos-kernel-packaging · GitHub". Github.com. Retrieved 2016-05-29. https://github.com/dankamongmen/sprezzos-kernel-packaging/blob/master/changelog