using System.Collections.Generic;
using System.Linq;

namespace YGNT.Infrastructure.Helper
{
    public static class ListStringHelp
    {
        /// <summary>
        /// 清除空格和连续空行
        /// </summary>
        /// <param name="listString"></param>
        /// <returns></returns>
        public static List<string> Trim(List<string> listString)
        {
            if (!listString.Any())
                return new List<string>();

            List<string> vs = new List<string>();
            string shang = listString.First().Trim();

            foreach (var item in listString)
            {
                string danQian = item.Trim();
                if (string.IsNullOrEmpty(shang) && string.IsNullOrEmpty(danQian))
                {

                }
                else
                {
                    vs.Add(danQian);
                }
                shang = danQian;
            }

            return vs;
        }

        /// <summary>
        /// 转为大写
        /// </summary>
        /// <param name="listString"></param>
        /// <returns></returns>
        public static List<string> ToUpper(List<string> listString)
        {
            if (!listString.Any())
                return new List<string>();

            List<string> vs = new List<string>();
            foreach (var item in listString)
            {
                vs.Add(item.ToUpper());
            }

            return vs;
        }

        /// <summary>
        /// 拆分：如[1,2][3],分解为[1][2][3]
        /// </summary>
        /// <param name="listString"></param>
        /// <returns></returns>
        public static List<string> Split(List<string> listString)
        {
            if (listString == null || !listString.Any())
                return new List<string>();

            List<string> vs = new List<string>();
            foreach (string item in listString)
            {
                foreach (char item2 in item)
                {
                    string v = item2.ToString();
                    if (!string.IsNullOrWhiteSpace(v))
                        vs.Add(v);
                }
            }

            return vs;
        }

    }
}
