StringExtensions
Extension methods to manipulate strings.
Extension methods to manipulate strings.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Methods79
Bigramsstring[]
public static string[] Bigrams(this string instance);Returns the bigrams (pairs of consecutive letters) of this string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string that will be used.
string[]The bigrams of this string.
BinToIntint
public static int BinToInt(this string instance);Converts a string containing a binary number into an integer.
Binary strings can either be prefixed with 0b or not,
and they can also start with a - before the optional prefix.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
intThe converted string.
CEscapestring
public static string CEscape(this string instance);Returns a copy of the string with special characters escaped using the C language standard.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to escape.
stringThe escaped string.
CUnescapestring
public static string CUnescape(this string instance);Returns a copy of the string with escaped characters replaced by their meanings according to the C language standard.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to unescape.
stringThe unescaped string.
Capitalizestring
public static string Capitalize(this string instance);Changes the case of some letters. Replace underscores with spaces, convert all letters
to lowercase then capitalize first and every letter following the space character.
For capitalize camelCase mixed_with_underscores it will return
Capitalize Camelcase Mixed With Underscores.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to capitalize.
stringThe capitalized string.
CasecmpToint
public static int CasecmpTo(this string instance, string to);Performs a case-sensitive comparison to another string and returns an integer that indicates their relative position in the sort order.
| Name | Type | Default |
|---|---|---|
instance | string | — |
to | string | — |
instanceThe string to compare.
toThe other string to compare.
intAn integer that indicates the lexical relationship between the two comparands.
CompareToint · Deprecated
public static int CompareTo(this string instance, string to, bool caseSensitive = true);Performs a comparison to another string and returns an integer that indicates their relative position in the sort order.
| Name | Type | Default |
|---|---|---|
instance | string | — |
to | string | — |
caseSensitive | bool | true |
instanceThe string to compare.
toThe other string to compare.
caseSensitiveIf true, the comparison will be case sensitive.
intAn integer that indicates the lexical relationship between the two comparands.
Countint
public static int Count(this string instance, string what, int from = 0, int to = 0, bool caseSensitive = true);Returns the number of occurrences of substring what in the string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
what | string | — |
from | int | 0 |
to | int | 0 |
caseSensitive | bool | true |
instanceThe string where the substring will be searched.
whatThe substring that will be counted.
fromIndex to start searching from.
toIndex to stop searching at.
caseSensitiveIf the search is case sensitive.
intNumber of occurrences of the substring in the string.
CountNint
public static int CountN(this string instance, string what, int from = 0, int to = 0);Returns the number of occurrences of substring what (ignoring case)
between PhysicsRayQueryParameters2D.From and PhysicsRayQueryParameters2D.To positions. If PhysicsRayQueryParameters2D.From
and PhysicsRayQueryParameters2D.To equals 0 the whole string will be used. If only PhysicsRayQueryParameters2D.To
equals 0 the remained substring will be used.
| Name | Type | Default |
|---|---|---|
instance | string | — |
what | string | — |
from | int | 0 |
to | int | 0 |
instanceThe string where the substring will be searched.
whatThe substring that will be counted.
fromIndex to start searching from.
toIndex to stop searching at.
intNumber of occurrences of the substring in the string.
Dedentstring
public static string Dedent(this string instance);Returns a copy of the string with indentation (leading tabs and spaces) removed.
See also StringExtensions.Indent to add indentation.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to remove the indentation from.
stringThe string with the indentation removed.
Find2 overloads
public static int Find(this string instance, char what, int from = 0, bool caseSensitive = true);Find the first occurrence of a char. Optionally, the search starting position can be passed.
| Name | Type | Default |
|---|---|---|
instance | string | — |
what | char | — |
from | int | 0 |
caseSensitive | bool | true |
instanceThe string that will be searched.
whatThe substring to find.
fromThe search starting position.
caseSensitiveIf true, the search is case sensitive.
intThe first instance of the char, or -1 if not found.
public static int Find(this string instance, string what, int from = 0, bool caseSensitive = true);Returns the index of the first occurrence of the specified string in this instance,
or -1. Optionally, the starting search index can be specified, continuing
to the end of the string.
Note: If you just want to know whether a string contains a substring, use the
System.String.Contains(System.String) method.
| Name | Type | Default |
|---|---|---|
instance | string | — |
what | string | — |
from | int | 0 |
caseSensitive | bool | true |
instanceThe string that will be searched.
whatThe substring to find.
fromThe search starting position.
caseSensitiveIf true, the search is case sensitive.
intThe starting position of the substring, or -1 if not found.
FindNint
public static int FindN(this string instance, string what, int from = 0);Returns the index of the first case-insensitive occurrence of the specified string in this instance,
or -1. Optionally, the starting search index can be specified, continuing
to the end of the string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
what | string | — |
from | int | 0 |
instanceThe string that will be searched.
whatThe substring to find.
fromThe search starting position.
intThe starting position of the substring, or -1 if not found.
GetBaseDirstring
public static string GetBaseDir(this string instance);If the string is a path to a file, return the base directory.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe path to a file.
stringThe base directory.
GetBaseNamestring
public static string GetBaseName(this string instance);If the string is a path to a file, return the path to the file without the extension.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe path to a file.
stringThe path to the file without the extension.
GetExtensionstring
public static string GetExtension(this string instance);Returns the extension without the leading period character (.)
if the string is a valid file name or path. If the string does not contain
an extension, returns an empty string instead.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe path to a file.
stringThe extension of the file or an empty string.
GetFilestring
public static string GetFile(this string instance);If the string is a path to a file, return the file and ignore the base directory.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe path to a file.
stringThe file name.
GetStringFromAsciistring
public static string GetStringFromAscii(this byte[] bytes);Converts ASCII encoded array to string.
Fast alternative to StringExtensions.GetStringFromUtf8 if the
content is ASCII-only. Unlike the UTF-8 function this function
maps every byte to a character in the array. Multibyte sequences
will not be interpreted correctly. For parsing user input always
use StringExtensions.GetStringFromUtf8.
| Name | Type | Default |
|---|---|---|
bytes | byte[] | — |
bytesA byte array of ASCII characters (on the range of 0-127).
stringA string created from the bytes.
GetStringFromUtf16string
public static string GetStringFromUtf16(this byte[] bytes);Converts UTF-16 encoded array to string using the little endian byte order.
| Name | Type | Default |
|---|---|---|
bytes | byte[] | — |
bytesA byte array of UTF-16 characters.
stringA string created from the bytes.
GetStringFromUtf32string
public static string GetStringFromUtf32(this byte[] bytes);Converts UTF-32 encoded array to string using the little endian byte order.
| Name | Type | Default |
|---|---|---|
bytes | byte[] | — |
bytesA byte array of UTF-32 characters.
stringA string created from the bytes.
GetStringFromUtf8string
public static string GetStringFromUtf8(this byte[] bytes);Converts UTF-8 encoded array to string.
Slower than StringExtensions.GetStringFromAscii but supports UTF-8
encoded data. Use this function if you are unsure about the
source of the data. For user input this function
should always be preferred.
| Name | Type | Default |
|---|---|---|
bytes | byte[] | — |
bytesA byte array of UTF-8 characters (a character may take up multiple bytes).
stringA string created from the bytes.
Hashuint
public static uint Hash(this string instance);Hash the string and return a 32 bits unsigned integer.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to hash.
uintThe calculated hash of the string.
HexDecodebyte[]
public static byte[] HexDecode(this string instance);Decodes a hexadecimal string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe hexadecimal string.
byte[]The byte array representation of this string.
HexEncodestring
public static string HexEncode(this byte[] bytes);Returns a hexadecimal representation of this byte array as a string.
| Name | Type | Default |
|---|---|---|
bytes | byte[] | — |
bytesThe byte array to encode.
stringThe hexadecimal representation of this byte array.
HexToIntint
public static int HexToInt(this string instance);Converts a string containing a hexadecimal number into an integer.
Hexadecimal strings can either be prefixed with 0x or not,
and they can also start with a - before the optional prefix.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
intThe converted string.
Indentstring
public static string Indent(this string instance, string prefix);Returns a copy of the string with lines indented with SpinBox.Prefix.
For example, the string can be indented with two tabs using "\t\t",
or four spaces using " ". The prefix can be any string so it can
also be used to comment out strings with e.g. "//.
See also StringExtensions.Dedent to remove indentation.
Note: Empty lines are kept empty.
| Name | Type | Default |
|---|---|---|
instance | string | — |
prefix | string | — |
instanceThe string to add indentation to.
prefixThe string to use as indentation.
stringThe string with indentation added.
IsAbsolutePathbool
public static bool IsAbsolutePath(this string instance);Returns true if the string is a path to a file or
directory and its starting point is explicitly defined. This includes
asset://, user://, C:\, /, etc.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to check.
boolIf the string is an absolute path.
IsRelativePathbool
public static bool IsRelativePath(this string instance);Returns true if the string is a path to a file or
directory and its starting point is implicitly defined within the
context it is being used. The starting point may refer to the current
directory (./), or the current Entity.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to check.
boolIf the string is a relative path.
IsSubsequenceOfbool
public static bool IsSubsequenceOf(this string instance, string text, bool caseSensitive = true);Check whether this string is a subsequence of the given string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
text | string | — |
caseSensitive | bool | true |
instanceThe subsequence to search.
textThe string that contains the subsequence.
caseSensitiveIf true, the check is case sensitive.
boolIf the string is a subsequence of the given string.
IsSubsequenceOfNbool
public static bool IsSubsequenceOfN(this string instance, string text);Check whether this string is a subsequence of the given string, ignoring case differences.
| Name | Type | Default |
|---|---|---|
instance | string | — |
text | string | — |
instanceThe subsequence to search.
textThe string that contains the subsequence.
boolIf the string is a subsequence of the given string.
IsValidFileNamebool
public static bool IsValidFileName(this string instance);Returns true if this string is free from characters that
aren't allowed in file names.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to check.
boolIf the string contains a valid file name.
IsValidFloatbool
public static bool IsValidFloat(this string instance);Returns true if this string contains a valid float.
This is inclusive of integers, and also supports exponents.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to check.
boolIf the string contains a valid floating point number.
IsValidHexNumberbool
public static bool IsValidHexNumber(this string instance, bool withPrefix = false);Returns true if this string contains a valid hexadecimal number.
If withPrefix is true, then a validity of the
hexadecimal number is determined by 0x prefix, for instance: 0xDEADC0DE.
| Name | Type | Default |
|---|---|---|
instance | string | — |
withPrefix | bool | false |
instanceThe string to check.
withPrefixIf the string must contain the 0x prefix to be valid.
boolIf the string contains a valid hexadecimal number.
IsValidHtmlColorbool
public static bool IsValidHtmlColor(this string instance);Returns true if this string contains a valid color in hexadecimal
HTML notation. Other HTML notations such as named colors or hsl() aren't
considered valid by this method and will return false.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to check.
boolIf the string contains a valid HTML color.
IsValidIPAddressbool
public static bool IsValidIPAddress(this string instance);Returns true if this string contains only a well-formatted
IPv4 or IPv6 address. This method considers reserved IP addresses such as
0.0.0.0 as valid.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to check.
boolIf the string contains a valid IP address.
IsValidIdentifierbool
public static bool IsValidIdentifier(this string instance);Returns true if this string is a valid identifier.
A valid identifier may contain only letters, digits and underscores (_)
and the first character may not be a digit.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to check.
boolIf the string contains a valid identifier.
IsValidIntbool
public static bool IsValidInt(this string instance);Returns true if this string contains a valid int.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to check.
boolIf the string contains a valid integer.
JSONEscapestring
public static string JSONEscape(this string instance);Returns a copy of the string with special characters escaped using the JSON standard.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to escape.
stringThe escaped string.
Leftstring
public static string Left(this string instance, int pos);Returns an amount of characters from the left of the string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
pos | int | — |
instanceThe original string.
posThe position in the string where the left side ends.
stringThe left side of the string from the given position.
Matchbool
public static bool Match(this string instance, string expr, bool caseSensitive = true);Do a simple case sensitive expression match, using ? and * wildcards.
| Name | Type | Default |
|---|---|---|
instance | string | — |
expr | string | — |
caseSensitive | bool | true |
instanceThe string to check.
exprExpression to check.
caseSensitiveIf true, the check will be case sensitive.
boolIf the expression has any matches.
MatchNbool
public static bool MatchN(this string instance, string expr);Do a simple case insensitive expression match, using ? and * wildcards.
| Name | Type | Default |
|---|---|---|
instance | string | — |
expr | string | — |
instanceThe string to check.
exprExpression to check.
boolIf the expression has any matches.
Md5Bufferbyte[]
public static byte[] Md5Buffer(this string instance);Returns the MD5 hash of the string as an array of bytes.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to hash.
byte[]The MD5 hash of the string.
Md5Textstring
public static string Md5Text(this string instance);Returns the MD5 hash of the string as a string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to hash.
stringThe MD5 hash of the string.
NocasecmpToint
public static int NocasecmpTo(this string instance, string to);Performs a case-insensitive comparison to another string and returns an integer that indicates their relative position in the sort order.
| Name | Type | Default |
|---|---|---|
instance | string | — |
to | string | — |
instanceThe string to compare.
toThe other string to compare.
intAn integer that indicates the lexical relationship between the two comparands.
PadDecimalsstring
public static string PadDecimals(this string instance, int digits);Format a number to have an exact number of digits
after the decimal point.
| Name | Type | Default |
|---|---|---|
instance | string | — |
digits | int | — |
instanceThe string to pad.
digitsAmount of digits after the decimal point.
stringThe string padded with zeroes.
PadZerosstring
public static string PadZeros(this string instance, int digits);Format a number to have an exact number of digits
before the decimal point.
| Name | Type | Default |
|---|---|---|
instance | string | — |
digits | int | — |
instanceThe string to pad.
digitsAmount of digits before the decimal point.
stringThe string padded with zeroes.
PathJoinstring
public static string PathJoin(this string instance, string file);If the string is a path, this concatenates VideoStream.File
at the end of the string as a subpath.
E.g. "this/is".PathJoin("path") == "this/is/path".
| Name | Type | Default |
|---|---|---|
instance | string | — |
file | string | — |
instanceThe path that will be concatenated.
fileFile name to concatenate with the path.
stringThe concatenated path with the given file name.
RFindint
public static int RFind(this string instance, string what, int from = -1, bool caseSensitive = true);Returns the index of the last occurrence of the specified string in this instance,
or -1. Optionally, the starting search index can be specified, continuing to
the beginning of the string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
what | string | — |
from | int | -1 |
caseSensitive | bool | true |
instanceThe string that will be searched.
whatThe substring to search in the string.
fromThe position at which to start searching.
caseSensitiveIf true, the search is case sensitive.
intThe position at which the substring was found, or -1 if not found.
RFindNint
public static int RFindN(this string instance, string what, int from = -1);Returns the index of the last case-insensitive occurrence of the specified string in this instance,
or -1. Optionally, the starting search index can be specified, continuing to
the beginning of the string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
what | string | — |
from | int | -1 |
instanceThe string that will be searched.
whatThe substring to search in the string.
fromThe position at which to start searching.
intThe position at which the substring was found, or -1 if not found.
ReplaceNstring
public static string ReplaceN(this string instance, string what, string forwhat);Replace occurrences of a substring for different ones inside the string, but search case-insensitive.
| Name | Type | Default |
|---|---|---|
instance | string | — |
what | string | — |
forwhat | string | — |
instanceThe string to modify.
whatThe substring to be replaced in the string.
forwhatThe substring that replaces what.
stringThe string with the substring occurrences replaced.
Rightstring
public static string Right(this string instance, int pos);Returns the right side of the string from a given position.
| Name | Type | Default |
|---|---|---|
instance | string | — |
pos | int | — |
instanceThe original string.
posThe position in the string from which the right side starts.
stringThe right side of the string from the given position.
Sha1Bufferbyte[]
public static byte[] Sha1Buffer(this string instance);Returns the SHA-1 hash of the string as an array of bytes.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to hash.
byte[]The SHA-1 hash of the string.
Sha1Textstring
public static string Sha1Text(this string instance);Returns the SHA-1 hash of the string as a string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to hash.
stringThe SHA-1 hash of the string.
Sha256Bufferbyte[]
public static byte[] Sha256Buffer(this string instance);Returns the SHA-256 hash of the string as an array of bytes.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to hash.
byte[]The SHA-256 hash of the string.
Sha256Textstring
public static string Sha256Text(this string instance);Returns the SHA-256 hash of the string as a string.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to hash.
stringThe SHA-256 hash of the string.
Similarityfloat
public static float Similarity(this string instance, string text);Returns the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar.
| Name | Type | Default |
|---|---|---|
instance | string | — |
text | string | — |
instanceThe string to compare.
textThe other string to compare.
floatThe similarity index.
SimplifyPathstring
public static string SimplifyPath(this string instance);Returns a simplified canonical path.
| Name | Type | Default |
|---|---|---|
instance | string | — |
stringSplitstring[]
public static string[] Split(this string instance, string divisor, bool allowEmpty = true);Split the string by a divisor string, return an array of the substrings. Example "One,Two,Three" will return ["One","Two","Three"] if split by ",".
| Name | Type | Default |
|---|---|---|
instance | string | — |
divisor | string | — |
allowEmpty | bool | true |
instanceThe string to split.
divisorThe divisor string that splits the string.
allowEmptyIf true, the array may include empty strings.
string[]The array of strings split from the string.
SplitFloatsfloat[]
public static float[] SplitFloats(this string instance, string divisor, bool allowEmpty = true);Split the string in floats by using a divisor string, return an array of the substrings. Example "1,2.5,3" will return [1,2.5,3] if split by ",".
| Name | Type | Default |
|---|---|---|
instance | string | — |
divisor | string | — |
allowEmpty | bool | true |
instanceThe string to split.
divisorThe divisor string that splits the string.
allowEmptyIf true, the array may include empty floats.
float[]The array of floats split from the string.
StripEdgesstring
public static string StripEdges(this string instance, bool left = true, bool right = true);Returns a copy of the string stripped of any non-printable character (including tabulations, spaces and line breaks) at the beginning and the end. The optional arguments are used to toggle stripping on the left and right edges respectively.
| Name | Type | Default |
|---|---|---|
instance | string | — |
left | bool | true |
right | bool | true |
instanceThe string to strip.
leftIf the left side should be stripped.
rightIf the right side should be stripped.
stringThe string stripped of any non-printable characters.
StripEscapesstring
public static string StripEscapes(this string instance);Returns a copy of the string stripped of any escape character.
These include all non-printable control characters of the first page
of the ASCII table (< 32), such as tabulation (\t) and
newline (\n and \r) characters, but not spaces.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to strip.
stringThe string stripped of any escape characters.
Substrstring
public static string Substr(this string instance, int from, int len);Returns part of the string from the position PhysicsRayQueryParameters2D.From, with length len.
| Name | Type | Default |
|---|---|---|
instance | string | — |
from | int | — |
len | int | — |
instanceThe string to slice.
fromThe position in the string that the part starts from.
lenThe length of the returned part.
stringPart of the string from the position PhysicsRayQueryParameters2D.From, with length len.
ToAsciiBufferbyte[]
public static byte[] ToAsciiBuffer(this string instance);Converts the String (which is a character array) to PackedByteArray (which is an array of bytes).
The conversion is faster compared to StringExtensions.ToUtf8Buffer,
as this method assumes that all the characters in the String are ASCII characters.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
byte[]The string as ASCII encoded bytes.
ToCamelCasestring
public static string ToCamelCase(this string instance);Returns the string converted to camelCase.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
stringThe converted string.
ToFloatfloat
public static float ToFloat(this string instance);Converts a string, containing a decimal number, into a float.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
floatThe number representation of the string.
ToIntint
public static int ToInt(this string instance);Converts a string, containing an integer number, into an int.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
intThe number representation of the string.
ToKebabCasestring
public static string ToKebabCase(this string instance);Returns the string converted to kebab-case.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
stringThe converted string.
ToPascalCasestring
public static string ToPascalCase(this string instance);Returns the string converted to PascalCase.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
stringThe converted string.
ToSnakeCasestring
public static string ToSnakeCase(this string instance);Returns the string converted to snake_case.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
stringThe converted string.
ToUtf16Bufferbyte[]
public static byte[] ToUtf16Buffer(this string instance);Converts the string (which is an array of characters) to a UTF-16 encoded array of bytes.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
byte[]The string as UTF-16 encoded bytes.
ToUtf32Bufferbyte[]
public static byte[] ToUtf32Buffer(this string instance);Converts the string (which is an array of characters) to a UTF-32 encoded array of bytes.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
byte[]The string as UTF-32 encoded bytes.
ToUtf8Bufferbyte[]
public static byte[] ToUtf8Buffer(this string instance);Converts the string (which is an array of characters) to a UTF-8 encoded array of bytes.
The conversion is a bit slower than StringExtensions.ToAsciiBuffer,
but supports all UTF-8 characters. Therefore, you should prefer this function
over StringExtensions.ToAsciiBuffer.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to convert.
byte[]The string as UTF-8 encoded bytes.
TrimPrefixstring
public static string TrimPrefix(this string instance, string prefix);Removes a given string from the start if it starts with it or leaves the string unchanged.
| Name | Type | Default |
|---|---|---|
instance | string | — |
prefix | string | — |
instanceThe string to remove the prefix from.
prefixThe string to remove from the start.
stringA copy of the string with the prefix string removed from the start.
TrimSuffixstring
public static string TrimSuffix(this string instance, string suffix);Removes a given string from the end if it ends with it or leaves the string unchanged.
| Name | Type | Default |
|---|---|---|
instance | string | — |
suffix | string | — |
instanceThe string to remove the suffix from.
suffixThe string to remove from the end.
stringA copy of the string with the suffix string removed from the end.
URIDecodestring
public static string URIDecode(this string instance);Decodes a string in URL encoded format. This is meant to
decode parameters in a URL when receiving an HTTP request.
This mostly wraps around System.Uri.UnescapeDataString(System.String),
but also handles +.
See StringExtensions.URIEncode for encoding.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to decode.
stringThe unescaped string.
URIEncodestring
public static string URIEncode(this string instance);Encodes a string to URL friendly format. This is meant to
encode parameters in a URL when sending an HTTP request.
This wraps around System.Uri.EscapeDataString(System.String).
See StringExtensions.URIDecode for decoding.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to encode.
stringThe escaped string.
ValidateNodeNamestring
public static string ValidateNodeName(this string instance);Removes any characters from the string that are prohibited in
Entity names (. : @ / ").
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to sanitize.
stringThe string sanitized as a valid node name.
XMLEscapestring
public static string XMLEscape(this string instance);Returns a copy of the string with special characters escaped using the XML standard.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to escape.
stringThe escaped string.
XMLUnescapestring
public static string? XMLUnescape(this string instance);Returns a copy of the string with escaped characters replaced by their meanings according to the XML standard.
| Name | Type | Default |
|---|---|---|
instance | string | — |
instanceThe string to unescape.
stringThe unescaped string.