Module std.string
String handling functions.
Category | Functions |
---|---|
Searching | column
inPattern
indexOf
indexOfAny
indexOfNeither
lastIndexOf
lastIndexOfAny
lastIndexOfNeither
|
Comparison | countchars
isNumeric
|
Mutation | capitalize
munch
removechars
squeeze
|
Pruning and Filling | center
chomp
chompPrefix
chop
detabber
detab
entab
leftJustify
outdent
rightJustify
strip
stripLeft
stripRight
wrap
|
Substitution | abbrev
soundex
soundexer
succ
tr
translate
|
Miscellaneous | assumeUTF
fromStringz
lineSplitter
representation
splitLines
toStringz
|
Objects of types string
, wstring
, and dstring
are value types
and cannot be mutated element-by-element. For using mutation during building
strings, use char[]
, wchar[]
, or dchar[]
. The xxxstring
types are preferable because they don't exhibit undesired aliasing, thus
making code more robust.
The following functions are publicly imported:
Module | Functions |
---|---|
Publicly imported functions | |
std.algorithm | cmp.html#algorithm">cmp
endsWith.html#algorithm">endsWith startsWith.html#algorithm">startsWith
|
std.array |
join replace replaceInPlace split |
std.format | format sformat |
std.uni |
icmp toLower toLowerInPlace toUpper toUpperInPlace |
There is a rich set of functions for string handling defined in other modules.
Functions related to Unicode and ASCII are found in std.uni
and std.ascii
, respectively. Other functions that have a
wider generality than just strings can be found in
std.algorithm and std.range.
See Also
- std.algorithm and std.range for generic range algorithms
-
std.ascii
for functions that work with ASCII strings -
std.uni
for functions that work with unicode strings
Functions
Name | Description |
---|---|
abbrev
|
Construct an associative array consisting of all
abbreviations that uniquely map to the strings in values .
|
assumeUTF
|
Assume the given array of integers is a well-formed UTF string and
return it typed as a UTF string.
|
capitalize
|
Capitalize the first character of and convert the rest of
to lowercase.
|
center
|
Center in a field characters wide.
is the character that will be used to fill up the space in the field that
doesn't fill.
|
centerJustifier
|
Center justify in a field characters wide.
is the character that will be used to fill up the space in the field that
doesn't fill.
|
chomp
|
If ends with , then is returned without
on its end. If it does not end with
, then it is returned unchanged.
|
chompPrefix
|
If starts with , then the part of following
is returned. If does not start with
|
chop
|
Returns without its last character, if there is one. If
ends with "\r\n" , then both are removed. If is empty, then
then it is returned unchanged.
|
column
|
Compute column number at the end of the printed form of the string, assuming the string starts in the leftmost column, which is numbered starting from 0. |
countchars
|
Count characters in s that match pattern .
|
detab
|
Replace each tab character in with the number of spaces necessary
to align the following character at the next tab stop.
|
detabber
|
Replace each tab character in with the number of spaces necessary
to align the following character at the next tab stop.
|
entab
|
Replaces spaces in with the optimal number of tabs.
All spaces and tabs at the end of a line are removed.
|
entabber
|
Replaces spaces in range with the optimal number of tabs.
All spaces and tabs at the end of a line are removed.
|
fromStringz
|
Returns a D-style array of char given a zero-terminated C-style string.
The returned array will retain the same type qualifiers as the input.
|
indexOf
|
Searches for character in range. |
indexOf
|
Returns the index of the first occurrence of in with
respect to the start index . If is not found, then
-1 is returned. If is found the value of the returned index
is at least . represents a codeunit index in
. If the sequence starting at does not represent a well
formed codepoint, then a std.utf.UTFException may be thrown.
|
indexOf
|
Searches for substring in .
|
indexOf
|
Searches for character in range starting at index startIdx .
|
indexOfAny
|
Returns the index of the first occurence of any of the elements in in . If no element of is found,
then -1 is returned. The slices s in the following
way . represents a codeunit
index in . If the sequence ending at does not
represent a well formed codepoint, then a std.utf.UTFException may be
thrown.
|
indexOfAny
|
Returns the index of the first occurence of any of the elements in in . If no element of is found,
then -1 is returned.
|
indexOfNeither
|
Returns the index of the first occurence of any character not an elements
in in . If all element of are
element of -1 is returned.
|
indexOfNeither
|
Returns the index of the first occurence of any character not an elements
in in . If all element of are
element of -1 is returned.
|
inPattern
|
See if character c is in the intersection of the patterns .
|
inPattern
|
See if character c is in the pattern .
|
isNumeric
|
[in] string s can be formatted in the following ways:
|
lastIndexOf
|
Returns the index of the last occurrence of in . If
is not found, then -1 is returned. The slices in
the following way . represents a
codeunit index in . If the sequence ending at does not
represent a well formed codepoint, then a std.utf.UTFException may be
thrown.
|
lastIndexOf
|
Returns the index of the last occurrence of in . If
is not found, then -1 is returned.
|
lastIndexOf
|
Returns the index of the last occurrence of in . If is
not found, then -1 is returned. The slices in
the following way . represents a
codeunit index in . If the sequence ending at does not
represent a well formed codepoint, then a std.utf.UTFException may be
thrown.
|
lastIndexOf
|
Returns the index of the last occurrence of in . If
is not found, then -1 is returned.
|
lastIndexOfAny
|
Returns the index of the last occurence of any of the elements in in . If no element of is found,
then -1 is returned. The slices s in the following
way s[0 .. . represents a codeunit index in
s . If the sequence ending at startIdx does not represent a well
formed codepoint, then a std.utf.UTFException may be thrown.
|
lastIndexOfAny
|
Returns the index of the last occurence of any of the elements in in . If no element of is found,
then -1 is returned.
|
lastIndexOfNeither
|
Returns the last index of the first occurence of any character that is not
an elements in in . If all element of
are element of -1 is returned.
|
lastIndexOfNeither
|
Returns the last index of the first occurence of any character that is not
an elements in in . If all element of
are element of -1 is returned.
|
leftJustifier
|
Left justify s in a field characters wide.
is the character that will be used to fill up the space in the field that
s doesn't fill.
|
leftJustify
|
Left justify in a field characters wide.
is the character that will be used to fill up the space in the field that
doesn't fill.
|
lineSplitter
|
Split an array or slicable range of characters into a range of lines
using '\ , '\n' , '\v' , '\f' , "\ ,
std.uni.lineSep , std.uni.paraSep and '\u0085' (NEL)
as delimiters. If keepTerm is set to KeepTerminator.yes , then the
delimiter is included in the slices returned.
|
makeTrans
|
Do same thing as makeTransTable but allocate the translation table
on the GC heap.
|
makeTransTable
|
Construct 256 character translation table, where characters in from [] are replaced
by corresponding characters in to [].
|
munch
|
Finds the position pos of the first character in s that does not match pattern (in the terminology used by
inPattern ). Updates s =
s [pos..$]. Returns the slice from the beginning of the original
(before update) string up to, and excluding, pos.
|
outdent
|
Removes one level of indentation from an array of single-line strings. |
outdent
|
Removes one level of indentation from a multi-line string. |
removechars
|
Return string that is s with all characters removed that match pattern .
|
representation
|
Returns the representation of a string, which has the same type
as the string except the character type is replaced by ubyte ,
ushort , or uint depending on the character width.
|
rightJustifier
|
Right justify s in a field characters wide.
is the character that will be used to fill up the space in the field that
s doesn't fill.
|
rightJustify
|
Right justify in a field characters wide.
is the character that will be used to fill up the space in the field that
doesn't fill.
|
soundex
|
Like soundexer , but with different parameters
and return value.
|
soundexer
|
Soundex algorithm. |
splitLines
|
Split into an array of lines according to the unicode standard using
'\r' , '\n' , "\r\n" , std.uni.lineSep ,
std.uni.paraSep , U+0085 (NEL), '\v' and '\f'
as delimiters. If is set to KeepTerminator.yes , then the
delimiter is included in the strings returned.
|
squeeze
|
Return string where sequences of a character in s [] from pattern []
are replaced with a single instance of that character.
If pattern is null, it defaults to all characters.
|
strip
|
Strips both leading and trailing whitespace (as defined by
std.uni.isWhite ).
|
stripLeft
|
Strips leading whitespace (as defined by std.uni.isWhite ).
|
stripRight
|
Strips trailing whitespace (as defined by std.uni.isWhite ).
|
succ
|
Return string that is the 'successor' to s [].
If the rightmost character is a-zA-Z0-9, it is incremented within
its case or digits. If it generates a carry, the process is
repeated with the one to its immediate left.
|
toStringz
|
Returns a C-style zero-terminated string equivalent to .
must not contain embedded '\0' 's as any C function will treat the first
'\0' that it sees as the end of the string. If s.empty is
true , then a string containing only '\0' is returned.
|
tr
|
Replaces the characters in which are in with the
the corresponding characters in and returns the resulting string.
|
translate
|
This is an overload of which takes an existing buffer to write the contents to.
|
translate
|
This is an ASCII-only overload of which takes an existing buffer to write the contents to.
|
translate
|
This is an overload of which takes an existing buffer to write the contents to.
|
translate
|
Replaces the characters in which are keys in with
their corresponding values in . is an AA
where its keys are dchar and its values are either dchar or some
type of string. Also, if is given, the characters in it are
removed from prior to translation. itself is unaltered.
A copy with the changes is returned.
|
translate
|
This is an ASCII-only overload of translate. It will not work with Unicode. It exists as an optimization for the cases where Unicode processing is not necessary. |
wrap
|
Wrap text into a paragraph. |
Classes
Name | Description |
---|---|
StringException
|
Exception thrown on errors in std.string functions.
|
Aliases
Name | Type | Description |
---|---|---|
CaseSensitive
|
Flag!("caseSensitive")
|
Flag indicating whether a search is case-sensitive. |
KeepTerminator
|
Flag!("keepTerminator")
|
Split s into an array of lines according to the unicode standard using
'\r' , '\n' , "\r\n" , std.uni.lineSep ,
std.uni.paraSep , U+0085 (NEL), '\v' and '\f'
as delimiters. If keepTerm is set to KeepTerminator.yes , then the
delimiter is included in the strings returned.
|
Authors
Walter Bright, Andrei Alexandrescu, and Jonathan M Davis