Hardly.StringHelpers.Tokenize C# (CSharp) Method

Tokenize() public static method

public static Tokenize ( this source, string token = ",", bool includeToken = false ) : string[]
source this
token string
includeToken bool
return string[]
        public static string[] Tokenize(this string source, string token = ",", bool includeToken = false)
        {
            if(token != null && token.Length > 0) {
                LinkedList<string> results = new LinkedList<string>();

                while(true) {
                    string result = GetBefore(source, token);
                    if(result == null) {
                        break;
                    }
                    if(result.Length > 0) {
                        if(includeToken) {
                            result += token;
                        }
                        results.AddLast(result);
                    }
                    source = GetAfter(source, token);
                }

                if(includeToken && source.StartsWith(token)) {
                    source += token;
                }
                results.AddLast(source);

                return results.ToArray();
            } else {
                Debug.Fail();
            }

            return null;
        }