2020-02-04 00:41:35 -05:00
|
|
|
using System;
|
2025-01-14 20:55:39 -05:00
|
|
|
using System.Text.RegularExpressions;
|
2020-02-04 00:41:35 -05:00
|
|
|
|
2018-09-21 00:25:10 -04:00
|
|
|
namespace ACE.Common.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class StringExtensions
|
|
|
|
|
{
|
|
|
|
|
public static bool StartsWithVowel(this string s)
|
|
|
|
|
{
|
2019-04-10 20:48:34 -05:00
|
|
|
if (string.IsNullOrEmpty(s))
|
2018-09-21 00:25:10 -04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
char firstLetter = s.ToLower()[0];
|
|
|
|
|
bool isVowel = "aeiou".IndexOf(firstLetter) >= 0;
|
|
|
|
|
|
|
|
|
|
return isVowel;
|
|
|
|
|
}
|
2019-03-28 00:26:25 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// For objects that don't have a PropertyString.PluralName
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string Pluralize(this string name)
|
|
|
|
|
{
|
2020-10-26 23:54:37 -04:00
|
|
|
if (name.EndsWith("us"))
|
|
|
|
|
return name + "s"; // This should be i but pcap shows "You have killed 4 Sarcophaguss! Your task is complete!"
|
|
|
|
|
//return name.Substring(0, name.Length - 2) + "i"; // "You have killed 4 Sarcophagi! Your task is complete!"
|
|
|
|
|
else if (name.EndsWith("ch") || name.EndsWith("s") || name.EndsWith("sh") || name.EndsWith("x") || name.EndsWith("z"))
|
2019-03-28 00:26:25 -04:00
|
|
|
return name + "es";
|
2020-10-22 13:46:18 -04:00
|
|
|
else if (name.EndsWith("th"))
|
|
|
|
|
return name;
|
2019-03-28 00:26:25 -04:00
|
|
|
else
|
|
|
|
|
return name + "s";
|
|
|
|
|
}
|
2020-02-04 00:41:35 -05:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes a string from the beginning of a string
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string TrimStart(this string result, string trimStart)
|
|
|
|
|
{
|
|
|
|
|
if (result.StartsWith(trimStart, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
result = result.Substring(trimStart.Length);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes a string from the end of a string
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string TrimEnd(this string result, string trimEnd)
|
|
|
|
|
{
|
|
|
|
|
if (result.EndsWith(trimEnd, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
result = result.Substring(0, result.Length - trimEnd.Length);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2025-01-14 20:55:39 -05:00
|
|
|
|
|
|
|
|
public static string WildCardToRegular(this string value)
|
|
|
|
|
{
|
|
|
|
|
return "^" + Regex.Escape(value).Replace("\\*", ".*") + "$";
|
|
|
|
|
}
|
2018-09-21 00:25:10 -04:00
|
|
|
}
|
|
|
|
|
}
|