Class StringExtensions
System.String Based Extension Methods
Inheritance
Namespace: GDX
Syntax
[VisualScriptingCompatible((short)2)]
public static class StringExtensions
Fields
| Improve this Doc View SourceAsciiCaseShift
The ASCII decimal value shift required to change the case of a letter.
Declaration
public const int AsciiCaseShift = 32
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiLowerCaseEnd
The ASCII decimal value for lowercase z.
Declaration
public const int AsciiLowerCaseEnd = 122
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiLowerCaseStart
The ASCII decimal value for a.
Declaration
public const int AsciiLowerCaseStart = 97
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiNumberDecimal
The ASCII decimal value for the decimal (.).
Declaration
public const int AsciiNumberDecimal = 46
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiNumberEnd
The ASCII decimal value for 9.
Declaration
public const int AsciiNumberEnd = 57
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiNumberSeparator
The ASCII decimal value for the , separator.
Declaration
public const int AsciiNumberSeparator = 47
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiNumberSign
The ASCII decimal value for the number sign -.
Declaration
public const int AsciiNumberSign = 45
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiNumberStart
The ASCII decimal value for 0.
Declaration
public const int AsciiNumberStart = 48
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiUpperCaseEnd
The ASCII decimal value for uppercase Z.
Declaration
public const int AsciiUpperCaseEnd = 90
Field Value
Type | Description |
---|---|
System.Int32 |
AsciiUpperCaseStart
The ASCII decimal value for uppercase A.
Declaration
public const int AsciiUpperCaseStart = 65
Field Value
Type | Description |
---|---|
System.Int32 |
EncryptionDefaultKey
The default encryption key used when none is provided to the encryption related extensions.
Declaration
public static byte[] EncryptionDefaultKey
Field Value
Type | Description |
---|---|
System.Byte[] |
Remarks
You can change this at runtime during some sort of initialization pass to being something unique to your project, but it is not absolutely necessary. This must be a multiple of 8 bytes.
EncryptionInitializationVector
The IV (Initialization Vector) provided to the System.Security.Cryptography.DESCryptoServiceProvider.
Declaration
public static byte[] EncryptionInitializationVector
Field Value
Type | Description |
---|---|
System.Byte[] |
Remarks
You can change this at runtime during some sort of initialization pass to being something unique to your project, but it is not absolutely necessary. This must be a multiple of 8 bytes.
Methods
| Improve this Doc View SourceConcatenate(String[], String, Boolean)
Concatenate an array of strings into one unified string.
Declaration
public static string Concatenate(this string[] pieces, string delimiter = null, bool trailingDelimiter = false)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | pieces | An array of strings |
System.String | delimiter | An optional string which to use between |
System.Boolean | trailingDelimiter | Should a trailing |
Returns
Type | Description |
---|---|
System.String | A concatenated System.String. |
CountOccurence(String, Char)
Counts the number of times the needle (targetCharacter
) appears in the haystack (
targetString
).
Declaration
public static int CountOccurence(this string targetString, char targetCharacter)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The haystack. |
System.Char | targetCharacter | The needle. |
Returns
Type | Description |
---|---|
System.Int32 | The number of times |
Remarks
Specifically created to avoid using LINQ and avoid an allocation.
Decrypt(String, Byte[])
Decrypt an encrypted System.String created by Encrypt(String, Byte[]).
Declaration
public static string Decrypt(this string encryptedString, byte[] encryptionKey = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | encryptedString | The encrypted System.String. |
System.Byte[] | encryptionKey | The key used to encrypt the System.String. |
Returns
Type | Description |
---|---|
System.String | The decrypted System.String. |
Remarks
This will have quite a few allocations.
Encrypt(String, Byte[])
Encrypt a System.String utilizing a System.Security.Cryptography.DESCryptoServiceProvider.
Declaration
public static string Encrypt(this string decryptedString, byte[] encryptionKey = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | decryptedString | The original System.String. |
System.Byte[] | encryptionKey | The key to be used when encrypting the System.String. This must be a multiple of 8 bytes. |
Returns
Type | Description |
---|---|
System.String | The encrypted System.String. |
Remarks
This will have quite a few allocations.
GetAfterFirst(String, String, StringComparison)
Get the System.String after the first identified splitString
in
targetString
.
Declaration
public static string GetAfterFirst(this string targetString, string splitString, StringComparison comparison = StringComparison.Ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String to look in. |
System.String | splitString | The divider which the |
System.StringComparison | comparison | Specifies the culture, case, and sort rules to be used. |
Returns
Type | Description |
---|---|
System.String | The content following the |
GetAfterLast(String, String, StringComparison)
Get the System.String after the last identified splitString
in
targetString
.
Declaration
public static string GetAfterLast(this string targetString, string splitString, StringComparison comparison = StringComparison.Ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String to look in. |
System.String | splitString | The divider which the |
System.StringComparison | comparison | Specifies the culture, case, and sort rules to be used. |
Returns
Type | Description |
---|---|
System.String | The content following the |
GetBeforeFirst(String, String, StringComparison)
Get the System.String before the first identified splitString
in
targetString
.
Declaration
public static string GetBeforeFirst(this string targetString, string splitString, StringComparison comparison = StringComparison.Ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String to look in. |
System.String | splitString | The divider which the |
System.StringComparison | comparison | Specifies the culture, case, and sort rules to be used. |
Returns
Type | Description |
---|---|
System.String | The content before the |
GetBeforeLast(String, String, StringComparison)
Get the System.String before the last identified splitString
in
targetString
.
Declaration
public static string GetBeforeLast(this string targetString, string splitString, StringComparison comparison = StringComparison.Ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String to look in. |
System.String | splitString | The divider which the |
System.StringComparison | comparison | Specifies the culture, case, and sort rules to be used. |
Returns
Type | Description |
---|---|
System.String | The content before the |
GetStableHashCode(String)
Get the stable hash code value of targetString
.
Declaration
public static int GetStableHashCode(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Int32 | A System.Int32 value. |
Remarks
This loosely based on the Fowler–Noll–Vo (FNV) hash function. It's value will be identical to the value produced natively by processing a System.String with System.String.GetHashCode, but with no allocations and no virtual calls.
GetStableLowerCaseHashCode(String)
Get the stable hash code value of targetString
(converted to an uppercase
System.String).
Declaration
public static int GetStableLowerCaseHashCode(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Int32 | A System.Int32 value. |
Remarks
This loosely based on the Fowler–Noll–Vo (FNV) hash function. It's value will be identical to the value produced natively by processing a System.String with System.String.ToLower.System.String.GetHashCode, but with no allocations.
GetStableUpperCaseHashCode(String)
Get the stable hash code value of targetString
(converted to an uppercase
System.String).
Declaration
public static int GetStableUpperCaseHashCode(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Int32 | A System.Int32 value. |
Remarks
This loosely based on the Fowler–Noll–Vo (FNV) hash function. It's value will be identical to the value produced natively by processing a System.String with System.String.ToUpper.System.String.GetHashCode, but with no allocations.
HasLowerCase(String)
Determine if there are any lowercase letters in the provided targetString
.
Declaration
public static bool HasLowerCase(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if lowercase letters were found. |
HasUpperCase(String)
Determine if there are any uppercase letters in the provided targetString
.
Declaration
public static bool HasUpperCase(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if uppercase letters were found. |
IsBooleanPositiveValue(String)
Determine if the targetString
represents a positive boolean value arrangement.
Declaration
public static bool IsBooleanPositiveValue(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if the |
Examples
Useful method when trying to parse data for branching.
if(data["set"].IsBooleanPositiveValue())
{
ShouldBlueBox();
}
|
Improve this Doc
View Source
IsBooleanValue(String)
Determine if the targetString
represents a boolean value arrangement.
Declaration
public static bool IsBooleanValue(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if the |
IsIntegerValue(String)
Determine if the targetString
is an System.Int32 value.
Declaration
public static bool IsIntegerValue(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if it contains an System.Int32. |
Remarks
This method is meant for when you do not actually need the value returned, merely an evaluation if
the provided targetString
is an System.Int32. This does not qualify
System.Single values positively.
IsNumeric(String)
Is the targetString
a numeric value.
Declaration
public static bool IsNumeric(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if the |
Remarks
The following requirements must be met to be considered a valid number in this method:
-
The first character may be an indicator of its sign, an explicit acceptance of
-
is made. If prefixed with+
, the number will be found invalid. - A single decimal point
.
may be present in thetargetString
. - No alphabet characters are present in the
targetString
.
PartialMatch(SimpleList<String>, String)
Does the haystack
partially contain the needle
?
Declaration
public static bool PartialMatch(this SimpleList<string> haystack, string needle)
Parameters
Type | Name | Description |
---|---|---|
SimpleList<System.String> | haystack | A SimpleList<T> of System.Strings. |
System.String | needle | The System.String that is being looked for. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if found. |
PartialMatch(String[], String)
Does the haystack
partially contain the needle
?
Declaration
public static bool PartialMatch(this string[] haystack, string needle)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | haystack | An array of System.Strings. |
System.String | needle | The System.String that is being looked for. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if found. |
SplitCamelCase(String, String)
Create a new string, splitting an existing string up based on camel case formatting.
Declaration
public static string SplitCamelCase(this string targetString, string divider = " ")
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The target System.String. |
System.String | divider | The System.String to put in between the split System.String. |
Returns
Type | Description |
---|---|
System.String | A new System.String. |
StripNonAscii(String)
Remove non ASCII characters from a System.String.
Declaration
public static string StripNonAscii(this string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The System.String to be cleaned. |
Returns
Type | Description |
---|---|
System.String | A System.String without ASCII characters. |