ConvertString extension
Extension methods for String to provide various utilities for string manipulation, encoding, decoding, and hashing. This extension adds methods to the String class for tasks such as hashing the string using MD5, converting between different encoding formats (Base64, Base32), converting a string to an ObjectId, and generating slugs.
- on
Properties
- oID → ObjectId?
-
Available on String, provided by the ConvertString extension
Converts the string to an ObjectId, or returns null if the string is not a valid ObjectId. This method trims the string and attempts to parse it into an ObjectId. If parsing fails, it returns null. Returns an ObjectId if the string is a valid ObjectId; otherwise, returns null.no setter
Methods
-
fromBase32(
{String def = ''}) → String -
Available on String, provided by the ConvertString extension
Decodes the string from Base32 encoding and returns the resulting string. If decoding fails, the method returns a default value.defis the default value returned in case of a decoding error. Returns the decoded string if successful; otherwise, returnsdef. -
fromBase64(
{String def = ''}) → String -
Available on String, provided by the ConvertString extension
Decodes the string from Base64 encoding and returns the resulting string. If decoding fails, the method returns a default value.defis the default value returned in case of a decoding error. Returns the decoded string if successful; otherwise, returnsdef. -
isSlug(
) → bool -
Available on String, provided by the ConvertString extension
Checks if the string is a valid slug. This method compares the original string to its slugified version to determine if it is a valid slug. Returnstrueif the string is a valid slug; otherwise, returnsfalse. -
toBase32(
) → String -
Available on String, provided by the ConvertString extension
Encodes the string to Base32 format. This method encodes the string directly to Base32. -
toBase64(
) → String -
Available on String, provided by the ConvertString extension
Encodes the string to Base64 format. This method converts the string to bytes and then encodes those bytes to Base64. Returns a String representing the Base64 encoded version of the original string. -
toMd5(
) → String -
Available on String, provided by the ConvertString extension
Computes the MD5 hash of the string and returns it as a hexadecimal String. This method converts the string to bytes using UTF-8 encoding, then computes the MD5 hash and returns the hash as a hexadecimal string. Returns a String representing the MD5 hash of the original string. -
toSlug(
) → String -
Available on String, provided by the ConvertString extension
Converts the string to a slug by replacing spaces and non-alphanumeric characters. The resulting slug is lowercase and uses hyphens instead of spaces. Non-alphanumeric characters are removed. Returns the slugified version of the original string. -
unscapeHtml(
) → String -
Available on String, provided by the ConvertString extension
Unescapes HTML entities in the string. Returns the unescaped string.