using System;
namespace GameDevLibrary.Extensions
{
public static class StringExtensions
{
///
/// Cut off a string once it reaches a amount of characters and add '...' to the end of the string
///
///
///
///
public static string Truncate(this string value, int maxChars)
{
return value.Length <= maxChars ? value : value.Substring(0, maxChars) + "...";
}
///
/// Identify if a string is null or empty
///
///
///
public static bool IsNullOrEmpty(this string str)
{
return String.IsNullOrEmpty(str);
}
///
/// Identify if a string is not null or empty
///
///
///
public static bool IsNotNullOrEmpty(this string str)
{
return !str.IsNullOrEmpty();
}
///
/// Check if the string matches any of the search parameters
///
///
///
///
public static bool AnyMatch(this string str, params string[] search)
{
foreach (string s in search)
{
if (s.Equals(str, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
///
/// Reverses a given string
///
///
///
public static string Reverse(this string str)
{
char[] charArray = str.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
}
}