41 lines
865 B
C#
41 lines
865 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace MarkovGrams.Utilities
|
|
{
|
|
public static class LinqExtensions
|
|
{
|
|
public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
|
|
{
|
|
foreach (T item in enumerable)
|
|
{
|
|
action(item);
|
|
}
|
|
}
|
|
|
|
public static T ShiftAt<T>(this List<T> list, int index)
|
|
{
|
|
T item = list[index];
|
|
list.RemoveAt(index);
|
|
return item;
|
|
}
|
|
|
|
public static int CountCharInstances(this string str, char[] targets)
|
|
{
|
|
int result = 0;
|
|
for (int i = 0; i < str.Length; i++) {
|
|
for (int t = 0; t < targets.Length; t++)
|
|
if (str[i] == targets[t]) result++;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static bool StartsWithFast(this string str, string target)
|
|
{
|
|
if (str.Length < target.Length) return false;
|
|
return str.Substring(0, target.Length) == target;
|
|
}
|
|
}
|
|
}
|