예제 #1
0
        public String2[] Split(String2 source)
        {
            if (source.Length < 1)
            {
                throw new ArgumentNullException("The length of split for source is short.");
            }
            if (Length < source.Length)
            {
                return(new String2[] { Copy() });
            }
            int             count = 0;
            int             pre   = 0;
            int             peek  = 0;
            String2LinkNode fin   = new String2LinkNode();
            String2LinkNode node  = fin;

            while ((peek = IndexOf(source, pre)) > -1)
            {
                node = node.Add(SubString(pre, peek - pre));
                pre  = peek + source.Length;
                count++;
            }
            node = node.Add(SubString(pre, Length - pre));
            String2[] ret = new String2[count + 1];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = fin.Data;
                fin    = fin.Next;
            }
            return(ret);
        }
예제 #2
0
        public String2 Replace(String2 oldVal, String2 newVal)
        {
            if (oldVal.Length < 1)
            {
                throw new ArgumentNullException("Replace");
            }
            if (Length < oldVal.Length)
            {
                return(Copy());
            }
            int             pre  = 0;
            int             peek = 0;
            String2LinkNode fin  = new String2LinkNode();
            String2LinkNode node = fin;

            while ((peek = IndexOf(oldVal, pre)) > -1)
            {
                node = node.Add(SubString(pre, peek - pre));
                node = node.Add(newVal);
                pre  = peek + oldVal.Length + 1;
            }
            node = node.Add(SubString(pre, Length - pre));
            String2 ret = fin.Data;

            while (fin.Next != null)
            {
                fin = fin.Next;
                if (fin.IsNull())
                {
                    break;
                }
                ret += fin.Data;
            }
            return(ret);
        }