Class StringUtilities
Defines utilities related to string.
Inherited Members
Namespace: SdlSdl.LanguagePlatformCore
Assembly: Sdl.LanguagePlatform.Core.dll
Syntax
public static class StringUtilities
Methods
DetermineCasing(string)
Determines the casing as in StringUtilities.Casing for the input string. Casing.Mixed will be returned for the empty string.
Declaration
public static StringUtilities.Casing DetermineCasing(string s)
Parameters
Type | Name | Description |
---|---|---|
string | s | The input string (must not be null) |
Returns
Type | Description |
---|---|
StringUtilitiesCasing |
EndsWithAny(string, char[])
Returns true
if the string s
ends with any
of the characters in characterList
, and false
otherwise.
Declaration
public static bool EndsWithAny(string s, char[] characterList)
Parameters
Type | Name | Description |
---|---|---|
string | s | |
char | characterList |
Returns
Type | Description |
---|---|
bool |
EscapeString(string)
Escapes all double quotes and backslashes in a string.
Declaration
public static string EscapeString(string s)
Parameters
Type | Name | Description |
---|---|---|
string | s | The input string. |
Returns
Type | Description |
---|---|
string | The string where all double quotes will be prefixed with a backslash. |
EscapeString(string, string)
Escapes special characters in a string, prefixing them with a backslash.
Declaration
public static string EscapeString(string s, string charactersToEscape)
Parameters
Type | Name | Description |
---|---|---|
string | s | The input string. |
string | charactersToEscape | The characters to escape |
Returns
Type | Description |
---|---|
string | The string where all occurrences of any of the characters to escape are prefixed with a backslash. |
FullWidthToHalfWidth(string)
Perform full-width to half-width conversion
Declaration
public static string FullWidthToHalfWidth(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input |
Returns
Type | Description |
---|---|
string |
GenerateRandomWord(int, bool)
Generates a string which consists of random letters in the range [a-z] with the specified length.
Declaration
public static string GenerateRandomWord(int length, bool initialUpper)
Parameters
Type | Name | Description |
---|---|---|
int | length | The length of the string to be generated. |
bool | initialUpper | If true, the initial letter of the generated string will be converted to upper-case. If false, the initial letter will remain lower-case. |
Returns
Type | Description |
---|---|
string | A string which consists of a random sequence of letters [a-z] with the specified length. |
GetPrefixLength(string, char[])
Computes the length of the prefix of s
which entirely consists
of characters in prefixChars
. If either of the parameters is
null
or empty, 0
is returned.
Declaration
public static int GetPrefixLength(string s, char[] prefixChars)
Parameters
Type | Name | Description |
---|---|---|
string | s | The string |
char | prefixChars | The set of prefix characters |
Returns
Type | Description |
---|---|
int | The length of the prefix of |
GetSuffixLength(string, char[])
Computes the length of the suffix of s
which entirely consists
of characters in suffixChars
. If either of the parameters is
null
or empty, 0
is returned.
Declaration
public static int GetSuffixLength(string s, char[] suffixChars)
Parameters
Type | Name | Description |
---|---|---|
string | s | The string |
char | suffixChars | The set of suffix characters |
Returns
Type | Description |
---|---|
int | The length of the suffix of |
HalfWidthToFullWidth(string)
Converts half-width characters to full-width characters
Declaration
public static string HalfWidthToFullWidth(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | single byte string, halfwidth string |
Returns
Type | Description |
---|---|
string |
HalfWidthToFullWidth2(string)
Unlike HalfWidthToFullWidth(string), performs half-width to full-width conversion for all available characters, not just those under ASCII 127
Declaration
public static string HalfWidthToFullWidth2(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input |
Returns
Type | Description |
---|---|
string |
IsAllWhitespace(string)
Returns true if t
contains only whitespace characters (IsWhitespace(char)),
and false otherwise.
Declaration
public static bool IsAllWhitespace(string t)
Parameters
Type | Name | Description |
---|---|---|
string | t |
Returns
Type | Description |
---|---|
bool |
MergeStrings(string, string)
Appends each individual charater of b
to a
, if it is not
already present, and returns the result. If a
already contains
duplicates, they are kept.
Declaration
public static string MergeStrings(string a, string b)
Parameters
Type | Name | Description |
---|---|---|
string | a | The first string |
string | b | The second string |
Returns
Type | Description |
---|---|
string | A string which consists of the input string |
RemoveAll(string, Predicate<char>)
Computes a copy of s
in which all characters which
satisfy property
are removed.
Declaration
public static string RemoveAll(string s, Predicate<char> property)
Parameters
Type | Name | Description |
---|---|---|
string | s | The input string |
Predicatechar | property | The character property to test |
Returns
Type | Description |
---|---|
string |
StartWithAny(string, char[])
Returns true
if the string s
starts with any
of the characters in characterList
, and false
otherwise.
Declaration
public static bool StartWithAny(string s, char[] characterList)
Parameters
Type | Name | Description |
---|---|---|
string | s | |
char | characterList |
Returns
Type | Description |
---|---|
bool |
TrimEnd(string, char[], out string)
Trims off any character contained in the trimCharacters
from the
end of the specified string s
, and returns the remainder, as well
as the trimmed-off suffix in trimmedSuffix
. If either s
or trimCharacters
are null
or empty, the result will be equal
to s
and trimmedSuffix
will be null.
Declaration
public static string TrimEnd(string s, char[] trimCharacters, out string trimmedSuffix)
Parameters
Type | Name | Description |
---|---|---|
string | s | The input string |
char | trimCharacters | The set of characters to trim off at the start of |
string | trimmedSuffix | If any characters have been trimmed off, this out parameter will
contain the trimmed-off suffix. If no characters have been trimmed off, this out parameter will
be |
Returns
Type | Description |
---|---|
string | The remainder of |
TrimStart(string, char[], out string)
Trims off any character contained in the trimCharacters
from the
start of the specified string s
, and returns the remainder, as well
as the trimmed-off prefix in trimmedPrefix
. If either s
or trimCharacters
are null
or empty, the result will be equal
to s
and trimmedPrefix
will be null.
Declaration
public static string TrimStart(string s, char[] trimCharacters, out string trimmedPrefix)
Parameters
Type | Name | Description |
---|---|---|
string | s | The input string |
char | trimCharacters | The set of characters to trim off at the start of |
string | trimmedPrefix | If any characters have been trimmed off, this out parameter will
contain the trimmed-off prefix. If no characters have been trimmed off, this out parameter will
be |
Returns
Type | Description |
---|---|
string | The remainder of |