Class StringExtensions
- Namespace
- AetherUtils.Core.Extensions
- Assembly
- AetherUtils.Core.dll
Provides extension methods for manipulating string objects.
public static class StringExtensions
- Inheritance
-
StringExtensions
- Inherited Members
Methods
BytesFromString(string)
public static byte[] BytesFromString(this string value)
Parameters
Returns
BytesToEncodedBytes(byte[], HashEncoding)
Encode the byte array to the specified HashEncoding.
[UsedImplicitly]
public static byte[] BytesToEncodedBytes(this byte[] bytes, HashEncoding encoding)
Parameters
bytesbyte[]- A byte array to encode.
encodingHashEncoding- The HashEncoding to use.
Returns
BytesToEncodedString(byte[], HashEncoding)
Encode the byte array to the specified HashEncoding.
[UsedImplicitly]
public static string BytesToEncodedString(this byte[] bytes, HashEncoding encoding)
Parameters
bytesbyte[]- A byte array to encode.
encodingHashEncoding- The HashEncoding to use.
Returns
- string
- A string encoded using the specified HashEncoding.
CreateDragImage(string, Font)
Creates a new Bitmap image from the specified text. This image can then be used for a drag-drop
operation to
show a preview of the data being dragged.
[UsedImplicitly]
public static Bitmap CreateDragImage(this string text, Font font)
Parameters
Returns
- Bitmap
- A new Bitmap "screenshot" of the text.
DecodedBytesFromEncodedString(string, HashEncoding)
Decodes the encoded string according to the specified HashEncoding.
public static byte[] DecodedBytesFromEncodedString(this string value, HashEncoding encoding)
Parameters
valuestring- The encoded string.
encodingHashEncoding- The HashEncoding to use.
Returns
DecodedStringFromEncodedString(string, HashEncoding)
Decodes an encoded string according to the specified HashEncoding.
[UsedImplicitly]
public static string DecodedStringFromEncodedString(this string value, HashEncoding encoding)
Parameters
valuestring- The encoded string.
encodingHashEncoding- The HashEncoding to use.
Returns
DeserializeJson<T>(string)
Deserializes an object from a JSON string.
public static T? DeserializeJson<T>(this string json) where T : class
Parameters
Returns
- T
- The deserialized object or
nullif the deserialization failed.
Type Parameters
T- The type of object to deserialize to.
Exceptions
- ArgumentException
- If
jsonwasnullor empty.
DeserializeXml<T>(string)
Deserializes an object from an XML string.
public static T? DeserializeXml<T>(this string xml) where T : class
Parameters
Returns
- T
- The deserialized object or
nullif the deserialization failed.
Type Parameters
T- The type of object to deserialize to.
Exceptions
- ArgumentException
- If
xmlwasnullor empty.
FromSecureString(SecureString)
Convert a SecureString to an unsecured string.
[UsedImplicitly]
public static string FromSecureString(this SecureString secure)
Parameters
secureSecureString- The SecureString.
Returns
Exceptions
- ArgumentNullException
- If
securewasnull.
ImageFromString(string)
Convert the Base64 representation of a picture into a usable Image object for drawing.
[UsedImplicitly]
public static Image ImageFromString(this string base64)
Parameters
Returns
Exceptions
- ArgumentNullException
- If
base64wasnull. - FormatException
- If the input was not a valid Base64 string.
IsBase64Encoded(string)
Get a value indicating if the string appears to be Base64 encoded.
public static bool IsBase64Encoded(this string input)
Parameters
Returns
Exceptions
- ArgumentNullException
- If
inputwasnull.
IsHexEncoded(string)
Get a value indicating if the string appears to be Hex (Base16) encoded.
[UsedImplicitly]
public static bool IsHexEncoded(this string input)
Parameters
Returns
Exceptions
- ArgumentNullException
- If
inputwasnull.
OpenUrl(string)
Opens the specified URL in the default web browser.
[UsedImplicitly]
public static void OpenUrl(this string url)
Parameters
urlstring- The URL to open.
RemoveWhitespace(string)
Removes all whitespace characters from the specified string.
public static string RemoveWhitespace(this string str)
Parameters
strstring- The string to remove whitespace from.
Returns
- string
- A new string, without the whitespace characters.
StringToEncodedBytes(string, HashEncoding)
Encode the string to the specified HashEncoding.
[UsedImplicitly]
public static byte[] StringToEncodedBytes(this string value, HashEncoding encoding)
Parameters
valuestring- The string to encode.
encodingHashEncoding- The HashEncoding to use.
Returns
StringToEncodedString(string, HashEncoding)
Encode the string to the specified HashEncoding.
public static string StringToEncodedString(this string value, HashEncoding encoding)
Parameters
valuestring- The string to encode.
encodingHashEncoding- The HashEncoding to use.
Returns
- string
- A string encoded using the specified HashEncoding.
ToSecureString(string)
Convert an unsecure string value into a SecureString.
[UsedImplicitly]
public static SecureString ToSecureString(this string unsecure)
Parameters
Returns
- SecureString
- A new read-only SecureString.
Exceptions
- ArgumentNullException
- If
unsecurewasnull.
Trim(string, int)
Trims the string to be the length specified before a new-line character is inserted.
If the new-line character was inserted at the position of a period (.), the
new line is inserted at the index of (.) + 1.
If the line being checked contains a new-line character already, nothing is done for that line.
[UsedImplicitly]
public static TrimmedString Trim(this string input, int lineLength = 80)
Parameters
inputstring- The string to trim.
lineLengthint- The number of characters in the line; default is
80.
Returns
- TrimmedString
- A new TrimmedString containing the trimmed string and the number of new lines.
Exceptions
- ArgumentNullException
- If
inputwasnull.