2023-08-17 04:04:23 +00:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2023-07-21 15:15:30 +00:00
|
|
|
namespace BotSharp.Abstraction.Utilities;
|
|
|
|
|
|
|
|
|
|
public static class StringExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string IfNullOrEmptyAs(this string str, string defaultValue)
|
|
|
|
|
=> string.IsNullOrEmpty(str) ? defaultValue : str;
|
2023-07-28 03:12:12 +00:00
|
|
|
|
|
|
|
|
public static string SubstringMax(this string str, int maxLength)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
return str;
|
|
|
|
|
|
|
|
|
|
if (str.Length > maxLength)
|
|
|
|
|
return str.Substring(0, maxLength);
|
|
|
|
|
else
|
|
|
|
|
return str;
|
|
|
|
|
}
|
2023-08-17 04:04:23 +00:00
|
|
|
|
2023-08-28 18:57:51 +00:00
|
|
|
public static string[] SplitByNewLine(this string input)
|
|
|
|
|
{
|
|
|
|
|
return input.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
}
|
2023-07-21 15:15:30 +00:00
|
|
|
}
|