Example #1
0
        public static List <string> SplitLines(this string listWithOnePerLine, bool trimValues, bool stripDuplicates, bool caseSensitiveDuplicateMatch)
        {
            if (listWithOnePerLine == null)
            {
                return(new List <string>());
            }

            StringUtil.LowerCaseComparer lcc = new StringUtil.LowerCaseComparer();
            List <string> list = new List <string>();

            using (System.IO.StringReader reader = new System.IO.StringReader(listWithOnePerLine))
            {
                string val = reader.ReadLine();
                while (val != null)
                {
                    if (trimValues)
                    {
                        val = val.Trim();
                    }

                    if (val.Length > 0 || !trimValues)
                    {
                        if (stripDuplicates)
                        {
                            if (caseSensitiveDuplicateMatch)
                            {
                                if (!list.Contains(val))
                                {
                                    list.Add(val);
                                }
                            }
                            else if (!list.Contains(val, lcc))
                            {
                                list.Add(val);
                            }
                        }
                        else
                        {
                            list.Add(val);
                        }
                    }
                    val = reader.ReadLine();
                }
            }
            return(list);
        }
Example #2
0
        public static List <string> Split(this string delimitedList, char delimiter, bool trimValues, bool stripDuplicates, bool caseSensitiveDuplicateMatch)
        {
            if (delimitedList == null)
            {
                return(new List <string>());
            }

            StringUtil.LowerCaseComparer lcc = new StringUtil.LowerCaseComparer();
            List <string> list = new List <string>();

            string[] arr = delimitedList.Split(delimiter);
            for (int i = 0; i < arr.Length; i++)
            {
                string val = trimValues ? arr[i].Trim() : arr[i];
                if (val.Length > 0)
                {
                    if (stripDuplicates)
                    {
                        if (caseSensitiveDuplicateMatch)
                        {
                            if (!list.Contains(val))
                            {
                                list.Add(val);
                            }
                        }
                        else if (!list.Contains(val, lcc))
                        {
                            list.Add(val);
                        }
                    }
                    else
                    {
                        list.Add(val);
                    }
                }
            }
            return(list);
        }