Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another, similar approach that works on any valid X12 file to replace a single data value with another on a matching segment:</p> <pre><code>public void ReplaceData(string filePath, string segmentName, int elementPosition, int componentPosition, string oldData, string newData) { string text = File.ReadAllText(filePath); Match match = Regex.Match(text, @"^ISA(?&lt;e&gt;.).{100}(?&lt;c&gt;.)(?&lt;s&gt;.)(\w+.*?\k&lt;s&gt;)*IEA\k&lt;e&gt;\d*\k&lt;e&gt;\d*\k&lt;s&gt;$"); if (!match.Success) throw new InvalidOperationException("Not an X12 file"); char elementSeparator = match.Groups["e"].Value[0]; char componentSeparator = match.Groups["c"].Value[0]; char segmentTerminator = match.Groups["s"].Value[0]; var segments = text .Split(segmentTerminator) .Select(s =&gt; s.Split(elementSeparator) .Select(e =&gt; e.Split(componentSeparator)).ToArray()) .ToArray(); foreach (var segment in segments.Where(s =&gt; s[0][0] == segmentName &amp;&amp; s.Count() &gt; elementPosition &amp;&amp; s[elementPosition].Count() &gt; componentPosition &amp;&amp; s[elementPosition][componentPosition] == oldData)) { segment[elementPosition][componentPosition] = newData; } File.WriteAllText(filePath, string.Join(segmentTerminator.ToString(), segments .Select(e =&gt; string.Join(elementSeparator.ToString(), e.Select(c =&gt; string.Join(componentSeparator.ToString(), c)) .ToArray())) .ToArray())); } </code></pre> <p>The regular expression used validates a proper X12 interchange envelope and assures that all segments within the file contain at least a one character name element. It also parses out the element and component separators as well as the segment terminator.</p>
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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