Created
August 4, 2012 02:43
-
-
Save Buildstarted/3253682 to your computer and use it in GitHub Desktop.
Splits a string by delimiters but retails delimiter
This file contains hidden or 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
private IEnumerable<string> GetIdentifierParts(string source) | |
{ | |
char[] splitBy = new[] { '.', '#' }; | |
int start = 0; | |
int index = 0; | |
string previousCharacter = ""; | |
while ((index = source.IndexOfAny(splitBy, start)) != -1) | |
{ | |
index++; | |
index = Interlocked.Exchange(ref start, index); | |
yield return previousCharacter + source.Substring(index, start - index - 1); | |
previousCharacter = source.Substring(start - 1, 1); | |
} | |
if (start < source.Length) | |
{ | |
yield return previousCharacter + source.Substring(start); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment