Last active
October 2, 2018 18:09
-
-
Save NickStrupat/6bb888d7ee5298fcd8e52dddf401cab6 to your computer and use it in GitHub Desktop.
Split sentence into all possible combinations of sub-sentences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace WhaHappen | |
{ | |
public static class StringExtensions | |
{ | |
public static IEnumerable<String> SplitIntoAll(this String s, Char delimiter = ' ') | |
{ | |
return s.SplitIntoAll(delimiter.ToString()); | |
} | |
public static IEnumerable<String> SplitIntoAll(this String s, String delimiter = " ") | |
{ | |
var tokens = s.Split(delimiter, StringSplitOptions.RemoveEmptyEntries); | |
for (var i = 0; i != tokens.Length; i++) | |
for (var j = 1; j != tokens.Length - i; j++) | |
yield return String.Join(delimiter, tokens.Skip(i).Take(j)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment