bfr/BFR/Helpers/Extensions.cs
adroslice e671fd4185 Implemented filtering
- Also an additional extension method for later
2019-11-14 20:42:25 +01:00

31 lines
953 B
C#

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace BFR.Helpers
{
public static class IListExtensions
{
public static void ReplaceAll<T>(this IList<T> list, IEnumerable<T> replacement)
{
list.Clear();
foreach (var t in replacement)
list.Add(t);
}
}
public static class StringExtensions
{
public static string Replace(this string input, string pattern, string replacement, bool useRegex = false, bool useRegexReplace = false) =>
Regex.Replace(input,
useRegex ? pattern : Regex.Escape(pattern),
useRegexReplace ? replacement : replacement.Replace("$", "$$"));
public static bool RegexContains(this string input, string pattern)
{
try { return Regex.IsMatch(input, pattern); }
catch(Exception) { return false; }
}
}
}