CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Program
{
public static void Main()
{
var last = "CamelCase".SplitBy(char.IsUpper).Last();
Console.WriteLine(last);
}
}
public static class StringHelper
{
public static IEnumerable<string> SplitBy(this string source, Func<Char, bool> predicate)
{
if (source == null)
throw new ArgumentNullException("source");
if (predicate == null)
throw new ArgumentNullException("predicate");
var sb = new StringBuilder();
foreach (var ch in source)
{
if (predicate(ch))
{
if (sb.Length != 0)
yield return sb.ToString();
sb.Clear();
sb.Append(ch);
}
else
{
sb.Append(ch);
}
}
yield return sb.ToString();
}
}