Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There isn't anything built-in like that. The first problem is that by passing an arbitrary <code>Func&lt;IEnumerable&lt;T&gt;,T&gt;</code> to the enumerator, it won't know how many bytes it will need to "take" and pass to the function. A more reasonable approach is shown below, where you can pass a sequence to be replaced, and the other sequence to replace, and do a simple search for that.</p> <pre><code>public static class Extensions { public static IEnumerable&lt;T&gt; ReplaceSequence&lt;T&gt;(this IEnumerable&lt;T&gt; original, IEnumerable&lt;T&gt; toSearch, IEnumerable&lt;T&gt; toReplace) where T : IEquatable&lt;T&gt; { T[] toSearchItems = toSearch.ToArray(); List&lt;T&gt; window = new List&lt;T&gt;(); foreach (T value in original) { window.Add(value); if (window.Count == toSearchItems.Length) { bool match = true; for (int i = 0; i &lt; toSearchItems.Length; i++) { if (!toSearchItems[i].Equals(window[i])) { match = false; break; } } if (match) { foreach (T toReplaceValue in toReplace) { yield return toReplaceValue; } window.Clear(); } else { yield return window[0]; window.RemoveAt(0); } } } foreach (T value in window) { yield return value; } } } // http://stackoverflow.com/q/6751533/751090 public class StackOverflow_6751533 { public static void Test() { byte[] byteArray = new byte[] { 0x01, 0x02, 0x7E, 0x7E, 0x04 }; byte[] escapeSequence = new byte[] { 0x7E, 0x7E }; byte[] unescapedSequence = new byte[] { 0x7E }; byte[] outputBytes = byteArray.ReplaceSequence(escapeSequence, unescapedSequence).ToArray(); for (int i = 0; i &lt; outputBytes.Length; i++) { Console.Write("{0:X2} ", (int)outputBytes[i]); } Console.WriteLine(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload