String.Split() seems to be the best option here, but just for fun it is also possible to do with LINQ.
One of my implementations of String Calculator Kata uses this approach (no Split at all). See InternalAdd() method. I took functional approach with head and tail. You divide string to head and tail using .Take() and return head + recursive result of calling the same function for tail.
Sample code for one char delimiter is below (things are getting complicated when delimiters are getting longer):
private IEnumerable<string> BreakString(string source)
{
var delimiter = '/';
var head = source.TakeWhile(c => c != delimiter);
if (!head.Any())
{
yield break;
}
var tail = source.SkipWhile(c => c != delimiter)
.Skip(1);
yield return String.Join("", head);
foreach (var t in BreakString(String.Join("", tail)))
{
yield return t;
}
}
// usage
from s in BreakString(source)
You can also go further and get rid of String.Join() by tail.Aggregate(new StringBuilder(), (sb, c) => sb.Append(c)).ToString();
string.Split?Split()