BlackBytesBox.Unified.Core
  • API
Show / Hide Table of Contents
  • BlackBytesBox.Unified.Core.Extensions.StringExtensions
    • StringExtensions
    • ValidationsStringExtensions
  • BlackBytesBox.Unified.Core.Utilities.MainContext
    • MainContext

Class StringExtensions

Provides extension methods for string operations, enhancing the built-in string manipulation capabilities.

Inheritance
object
StringExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: BlackBytesBox.Unified.Core.Extensions.StringExtensions
Assembly: BlackBytesBox.Unified.Core.dll
Syntax
public static class StringExtensions

Methods

| Edit this page View Source

ToShortUUID(string?)

Generates a UUID for the given string using MD5 hashing and returns it as a string without hyphens.

Declaration
public static string ToShortUUID(this string? input)
Parameters
Type Name Description
string input

The input string for which to generate the UUID. If null, an empty string is used.

Returns
Type Description
string

A string representation of the UUID generated from the input string, without hyphens.

Examples
string uuid = "your-long-string-here".ToShortUUID();
| Edit this page View Source

TrimSpecific(string, char, int, int)

Trims occurrences of a specified character from the start and end of the string up to a defined count.

Declaration
public static string TrimSpecific(this string input, char charToTrim, int countFromStart, int countFromEnd)
Parameters
Type Name Description
string input

The string to trim. May be null or empty.

char charToTrim

The character to remove from both ends.

int countFromStart

The maximum number of occurrences to remove from the start.

int countFromEnd

The maximum number of occurrences to remove from the end.

Returns
Type Description
string

A new string with the specified character trimmed from the beginning and end according to the provided counts. Returns the original string if it is null or empty, or an empty string if all characters are trimmed.

Remarks

This extension method removes the charToTrim from the beginning of the string up to countFromStart times and from the end up to countFromEnd times. If the input is null or empty, it returns the input unchanged. If all characters are trimmed, an empty string is returned.

Examples
// Example usage:
string original = "###Hello World###";
string trimmed = original.TrimSpecific('#', 3, 3);
Console.WriteLine(trimmed); // Outputs: "Hello World"
  • Edit this page
  • View Source
In this article
Back to top