namespace adas_core.Domain.Utils;
///
/// Provides static extension methods for the type.
///
public static class StringEx
{
///
/// Determines whether the specified string is null or an empty string.
///
/// The string to evaluate.
/// true if is null or an empty string; otherwise, false.
public static bool IsEmpty(this string source)
{
return string.IsNullOrEmpty(source);
}
///
/// Determines whether the specified string is null, empty, or consists only of white-space characters.
///
/// The string to evaluate.
/// true if the string is null, empty, or contains only white space; otherwise, false.
public static bool IsEmptyOrWhiteSpace(this string source)
{
return string.IsNullOrWhiteSpace(source);
}
///
/// Returns the portion of the source string that follows the first occurrence of the specified value, using ordinal (case-sensitive, culture-insensitive) comparison. If the source or value is null or empty, or the value is not found within the source, the original source is returned unchanged.
///
/// The string to search within.
/// The delimiter whose first occurrence marks the start of the returned substring.
/// The substring after the first occurrence of ; otherwise, the original .
public static string SubstringAfter(this string source, string value)
{
if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(value)) return source;
var index = source.IndexOf(value, StringComparison.Ordinal);
return index >= 0
? source.Substring(index + value.Length)
: source;
}
///
/// Returns the portion of that precedes the first occurrence of , using ordinal comparison.
/// If either or is null or empty, or if is not found within , the original is returned unchanged.
///
/// The string to extract the substring from.
/// The delimiter whose first occurrence marks the end of the returned substring.
/// The substring of before the first occurrence of , or the original when no match is found or when either input is null or empty.
public static string SubstringBefore(this string source, string value)
{
if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(value)) return source;
var index = source.IndexOf(value, StringComparison.Ordinal);
return index >= 0
? source.Substring(0, index)
: source;
}
}