Exemplo n.º 1
0
        /// <summary>
        /// Performs deletion of specified slice.
        /// </summary>
        /// <param name="source">Source string.</param>
        /// <param name="from">First character index to delete.</param>
        /// <param name="to">Exclusive boundary.</param>
        /// <param name="step">Increment index by.</param>
        /// <exception cref="ArgumentNullException">source is null.</exception>
        /// <exception cref="ArgumentException">step is equal to 0.</exception>
        /// <returns>Result of slice deletion.</returns>
        public static string SliceDelete(
            this string source,
            int?from = null,
            int?to   = null,
            int step = 1)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var indexer = new SliceDeleteItemIndexer <int>(new ProxiedReadOnlyList <int>(new RangeIndexer(0, source.Length)), from, to, step);

            return(Enumerable.Range(0, indexer.Count)
                   .Aggregate(new StringBuilder(), (builder, i) => builder.Append(source[indexer.GetItemAt(i)]))
                   .ToString());
        }
Exemplo n.º 2
0
        internal static IList <T> GetSliceDelete <T>(IList <T> source, int?from, int?to, int step)
        {
            var indexer = new SliceDeleteItemIndexer <T>(source, from, to, step);

            return(new ProxiedReadOnlyList <T>(indexer));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Performs deletion of specified slice.
        /// </summary>
        /// <param name="source">Source string.</param>
        /// <param name="from">First character index to delete.</param>
        /// <param name="to">Exclusive boundary.</param>
        /// <param name="step">Increment index by.</param>
        /// <exception cref="ArgumentNullException">source is null.</exception>
        /// <exception cref="ArgumentException">step is equal to 0.</exception>
        /// <returns>Result of slice deletion.</returns>
        public static string SliceDelete(
            this string source,
            int? from = null,
            int? to = null,
            int step = 1)
        {
            if (source == null) throw new ArgumentNullException("source");

            var indexer = new SliceDeleteItemIndexer<int>(new ProxiedReadOnlyList<int>(new RangeIndexer(0, source.Length)), from, to, step);
            return Enumerable.Range(0, indexer.Count)
                             .Aggregate(new StringBuilder(), (builder, i) => builder.Append(source[indexer.GetItemAt(i)]))
                             .ToString();
        }