Class StringUtilities
Defines utilities related to System.String.
Inheritance
Inherited Members
Namespace: Sdl.LanguagePlatform.Core
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 |
---|---|---|
System.String | s | The input string (must not be null) |
Returns
Type | Description |
---|---|
StringUtilities.Casing |
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 |
---|---|---|
System.String | s | |
System.Char[] | characterList |
Returns
Type | Description |
---|---|
System.Boolean |
EscapeString(String)
Escapes all double quotes and backslashes in a string.
Declaration
public static string EscapeString(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The input string. |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.String | s | The input string. |
System.String | charactersToEscape | The characters to escape |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.String | input |
Returns
Type | Description |
---|---|
System.String |
GenerateRandomWord(Int32, Boolean)
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 |
---|---|---|
System.Int32 | length | The length of the string to be generated. |
System.Boolean | 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 |
---|---|
System.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 |
---|---|---|
System.String | s | The string |
System.Char[] | prefixChars | The set of prefix characters |
Returns
Type | Description |
---|---|
System.Int32 | 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 |
---|---|---|
System.String | s | The string |
System.Char[] | suffixChars | The set of suffix characters |
Returns
Type | Description |
---|---|
System.Int32 | 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 |
---|---|---|
System.String | input | single byte string, halfwidth string |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.String | input |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.String | t |
Returns
Type | Description |
---|---|
System.Boolean |
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 |
---|---|---|
System.String | a | The first string |
System.String | b | The second string |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.String | s | The input string |
System.Predicate<System.Char> | property | The character property to test |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.String | s | |
System.Char[] | characterList |
Returns
Type | Description |
---|---|
System.Boolean |
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 |
---|---|---|
System.String | s | The input string |
System.Char[] | trimCharacters | The set of characters to trim off at the start of |
System.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 |
---|---|
System.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 |
---|---|---|
System.String | s | The input string |
System.Char[] | trimCharacters | The set of characters to trim off at the start of |
System.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 |
---|---|
System.String | The remainder of |