/// <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()); }
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)); }
/// <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(); }