Exemplo n.º 1
0
 public static StringZone[] SplitZone(string sString, char[,] cCharZone)
 {
     StringZones sz = new StringZones(sString, cCharZone);
     return sz.SplitZone();
 }
Exemplo n.º 2
0
        private static string[] _Split(string s, char[] cSeparator, char[,] cCharZone, SplitOption splitOption)
        {
            char c;
            int i, ic, iDebutElement;
            string[] r;
            List<string> alSplit;
            StringZones sz;

            if (s == null) return new string[0];

            if (cCharZone == null)
                r = s.Split(cSeparator);
            else
            {
                // cCharZone tableau des caractères de délimitation des zones par exemple ( et )
                // le tableau doit avoir comme dimension [n,2]
                // split en tenant compte des zones de texte délimitées par cCharZone
                alSplit = new List<string>();
                sz = new StringZones(s, cCharZone);
                iDebutElement = 0;
                while ((ic = sz.ReadChar()) != -1)
                {
                    c = (char)ic;
                    if (Array.IndexOf(cSeparator, c) != -1)
                    {
                        alSplit.Add(s.Substring(iDebutElement, sz.IndexNextChar - 1 - iDebutElement));
                        iDebutElement = sz.IndexNextChar;
                    }
                }
                //if (sz.IndiceNextChar - 1 - iDebutElement > 0)
                if (sz.IndexNextChar - iDebutElement > 0)
                    alSplit.Add(s.Substring(iDebutElement, sz.IndexNextChar - iDebutElement));
                else
                    alSplit.Add("");
                r = new string[alSplit.Count];
                alSplit.CopyTo(r);
            }
            //if (bTrim)
            //    for(i = 0; i < r.Length; i++)  r[i] = r[i].Trim();
            //if (bRemoveDoubleQuot)
            //    for(i = 0; i < r.Length; i++)
            //    {
            //        s = r[i];
            //        if (s.StartsWith("\"") && s.EndsWith("\""))
            //            r[i] = s.Substring(1, s.Length - 2);
            //    }
            if ((splitOption & SplitOption.RemoveDoubleQuot) == SplitOption.RemoveDoubleQuot ||
                (splitOption & SplitOption.TrimStart) == SplitOption.TrimStart ||
                (splitOption & SplitOption.TrimEnd) == SplitOption.TrimEnd)
            {
                for (i = 0; i < r.Length; i++)
                {
                    s = r[i];
                    bool bNew = false;
                    if ((splitOption & SplitOption.RemoveDoubleQuot) == SplitOption.RemoveDoubleQuot)
                    {
                        if (s.StartsWith("\"") && s.EndsWith("\""))
                        {
                            s = s.Substring(1, s.Length - 2);
                            bNew = true;
                        }
                    }
                    if ((splitOption & SplitOption.Trim) == SplitOption.Trim)
                    {
                        s = s.Trim();
                        bNew = true;
                    }
                    else if ((splitOption & SplitOption.TrimStart) == SplitOption.TrimStart)
                    {
                        s = s.TrimStart();
                        bNew = true;
                    }
                    else if ((splitOption & SplitOption.TrimEnd) == SplitOption.TrimEnd)
                    {
                        s = s.TrimEnd();
                        bNew = true;
                    }
                    if (bNew) r[i] = s;
                }
            }
            //if (bRemoveEmpty)
            if ((splitOption & SplitOption.RemoveEmptyString) == SplitOption.RemoveEmptyString)
            {
                alSplit = new List<string>();
                for (i = 0; i < r.Length; i++) if (r[i] != "") alSplit.Add(r[i]);
                r = new string[alSplit.Count];
                alSplit.CopyTo(r);
            }
            return r;
        }
Exemplo n.º 3
0
        private static string[] _Split(string s, char[] cSeparator, char[,] cCharZone, SplitOption splitOption)
        {
            char c;
            int  i, ic, iDebutElement;

            string[]      r;
            List <string> alSplit;
            StringZones   sz;

            if (s == null)
            {
                return(new string[0]);
            }

            if (cCharZone == null)
            {
                r = s.Split(cSeparator);
            }
            else
            {
                // cCharZone tableau des caractères de délimitation des zones par exemple ( et )
                // le tableau doit avoir comme dimension [n,2]
                // split en tenant compte des zones de texte délimitées par cCharZone
                alSplit       = new List <string>();
                sz            = new StringZones(s, cCharZone);
                iDebutElement = 0;
                while ((ic = sz.ReadChar()) != -1)
                {
                    c = (char)ic;
                    if (Array.IndexOf(cSeparator, c) != -1)
                    {
                        alSplit.Add(s.Substring(iDebutElement, sz.IndexNextChar - 1 - iDebutElement));
                        iDebutElement = sz.IndexNextChar;
                    }
                }
                //if (sz.IndiceNextChar - 1 - iDebutElement > 0)
                if (sz.IndexNextChar - iDebutElement > 0)
                {
                    alSplit.Add(s.Substring(iDebutElement, sz.IndexNextChar - iDebutElement));
                }
                else
                {
                    alSplit.Add("");
                }
                r = new string[alSplit.Count];
                alSplit.CopyTo(r);
            }
            //if (bTrim)
            //    for(i = 0; i < r.Length; i++)  r[i] = r[i].Trim();
            //if (bRemoveDoubleQuot)
            //    for(i = 0; i < r.Length; i++)
            //    {
            //        s = r[i];
            //        if (s.StartsWith("\"") && s.EndsWith("\""))
            //            r[i] = s.Substring(1, s.Length - 2);
            //    }
            if ((splitOption & SplitOption.RemoveDoubleQuot) == SplitOption.RemoveDoubleQuot ||
                (splitOption & SplitOption.TrimStart) == SplitOption.TrimStart ||
                (splitOption & SplitOption.TrimEnd) == SplitOption.TrimEnd)
            {
                for (i = 0; i < r.Length; i++)
                {
                    s = r[i];
                    bool bNew = false;
                    if ((splitOption & SplitOption.RemoveDoubleQuot) == SplitOption.RemoveDoubleQuot)
                    {
                        if (s.StartsWith("\"") && s.EndsWith("\""))
                        {
                            s    = s.Substring(1, s.Length - 2);
                            bNew = true;
                        }
                    }
                    if ((splitOption & SplitOption.Trim) == SplitOption.Trim)
                    {
                        s    = s.Trim();
                        bNew = true;
                    }
                    else if ((splitOption & SplitOption.TrimStart) == SplitOption.TrimStart)
                    {
                        s    = s.TrimStart();
                        bNew = true;
                    }
                    else if ((splitOption & SplitOption.TrimEnd) == SplitOption.TrimEnd)
                    {
                        s    = s.TrimEnd();
                        bNew = true;
                    }
                    if (bNew)
                    {
                        r[i] = s;
                    }
                }
            }
            //if (bRemoveEmpty)
            if ((splitOption & SplitOption.RemoveEmptyString) == SplitOption.RemoveEmptyString)
            {
                alSplit = new List <string>();
                for (i = 0; i < r.Length; i++)
                {
                    if (r[i] != "")
                    {
                        alSplit.Add(r[i]);
                    }
                }
                r = new string[alSplit.Count];
                alSplit.CopyTo(r);
            }
            return(r);
        }
Exemplo n.º 4
0
        public static StringZone[] SplitZone(string sString, char[,] cCharZone)
        {
            StringZones sz = new StringZones(sString, cCharZone);

            return(sz.SplitZone());
        }