<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Ted,</div><div class=""><br class=""></div><div class="">Here’s a sketch of one way to handle this kind of processing without requiring integer indexing. Hopefully not too buggy though I haven’t tested it extensively :).&nbsp;</div><div class=""><br class=""></div><div class="">Here I’m stashing the parsed values in a dictionary, but you could also write code to insert them into a proper data structure where the dictionary set is happening (or maybe stick with the dictionary build, and then use that dictionary to populate your data structure, along with some more data validation and error handling).</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">import</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;Foundation</span></div><div style="margin: 0px; line-height: normal; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">String</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">Collection</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;{ }</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;fieldLengths:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">DictionaryLiteral</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;= [</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"CompanyName"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:30,</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"PresidentLastName"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:15,</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"PresidentFirstName"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:8,</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"VPMarketingLastName"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:15,</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"VPMarketingFirstName"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:8,</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"AlternateContactTitle"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:10,</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"AlternateContactLastName"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:15,</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"AlternateContactFirstName"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:8,</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"Address"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">:15,</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(180, 38, 26);" class="">"City"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">:15,</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(180, 38, 26);" class="">"State"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">:2,</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(180, 38, 26);" class="">"Zip"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">:5,</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">]</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;data =&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"Premier Properties&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Murray&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Mitch&nbsp;&nbsp;&nbsp;Ricky&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Roma&nbsp; &nbsp;&nbsp;Office MgrWilliamson&nbsp;&nbsp; &nbsp;&nbsp;John&nbsp; &nbsp;&nbsp;350 Fifth Av&nbsp;&nbsp;&nbsp;New York&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;NY10118"</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;keyedRecord: [</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">String</span><span style="font-variant-ligatures: no-common-ligatures;" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">String</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] = [:]</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">for</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;(key,length)&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">in</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">fieldLengths</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;field =&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">data</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">prefix</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(length)</span></div><p style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""></span><br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;field.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">count</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;== length</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">else</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">fatalError</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(180, 38, 26); font-variant-ligatures: no-common-ligatures;" class="">"Input too short while reading&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">\</span><span style="color: rgb(180, 38, 26); font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures;" class="">key</span><span style="color: rgb(180, 38, 26); font-variant-ligatures: no-common-ligatures;" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) }</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(0, 143, 0);" class="">// or however you want to handle it</span></span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">keyedRecord</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">[key] = field.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">trimmingCharacters</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">(in:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">CharacterSet</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">whitespaces</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">)</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">data</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;=&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">data</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">dropFirst</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">(length)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div><div style="margin: 0px; line-height: normal; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">data</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">isEmpty</span></div><div style="margin: 0px; line-height: normal; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">else</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;{&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">fatalError</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">(</span><span style="font-variant-ligatures: no-common-ligatures;" class="">"Input too long"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">) }</span></div><div class=""><br class=""></div></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">keyedRecord</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div></div></div><div class="">I think it’s worth noting how seductive it is, with the integer indexing, to perform unchecked indexing into the data:&nbsp;<span style="font-family: Avenir;" class="">recordStr[ 0..&lt;30]</span>&nbsp;is great until you have to process a corrupt record. Working in terms of higher-level APIs encourages handling of the failure cases. As an added bonus, when you upgrade your system and now the incoming data turns out to be utf8, your system doesn’t crash when a bored intern inserts some emoji into the president’s name.</div><div class=""><br class=""></div><div class="">There is still definitely room to make this easier/more discoverable for users:</div><div class=""><br class=""></div><div class="">- The “patterns” concept that is briefly touched on in the string manifesto would hopefully provide a another way of expressing this, with patterns matching fixed numbers of characters.</div><div class="">&nbsp;- The need to walk over the field multiple times (first prefix, then count, then dropFirst) should be better-handled by some other scanning APIs mentioned in the manifesto e.g.&nbsp;<span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">if</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">let</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""> field = </span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">data</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">.dropPrefix(lengthPattern)</span>. Note that if the underlying String held only ASCII/Latin1, these should still be constant-time operations under the hood.&nbsp;</div><div class="">- Another approach is to provide generic operations on Collection that chunks collections into subsequences of given lengths and serves them up, possibly via a a lazy view. This would have the advantage of not requiring mutable state in the loop.</div><div class=""><br class=""></div><div class="">But the above is what we can achieve with the tools we have today.</div><div class=""><br class=""></div><div class="">p.s. as someone who has worked in a bank with thousands of ancient file formats, no argument from me that COBOL rules :)</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Feb 10, 2017, at 9:20 AM, Ted F.A. van Gaalen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Please see in-line response below</span><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class="">On 10 Feb 2017, at 03:56, Shawn Erickson &lt;<a href="mailto:shawnce@gmail.com" class="">shawnce@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, Feb 9, 2017 at 5:09 PM Ted F.A. van Gaalen &lt;<a href="mailto:tedvgiosdev@gmail.com" class="">tedvgiosdev@gmail.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_msg" style="word-wrap: break-word;"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On 10 Feb 2017, at 00:11, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="gmail_msg" target="_blank">dabrahams@apple.com</a>&gt; wrote:</div><br class="gmail_msg m_-8685886003293606080Apple-interchange-newline"><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg">on Thu Feb 09 2017, "Ted F.A. van Gaalen" &lt;<a href="http://tedvgiosdev-at-gmail.com/" class="gmail_msg" target="_blank">tedvgiosdev-AT-gmail.com</a>&gt; wrote:<br class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg">Hello Shawn<br class="gmail_msg">Just google with any programming language name and “string manipulation”<br class="gmail_msg">and you have enough reading for a week or so :o)<br class="gmail_msg">TedvG<br class="gmail_msg"></blockquote><br class="gmail_msg">That truly doesn't answer the question.&nbsp; It's not, “why do people index<br class="gmail_msg">strings with integers when that's the only tool they are given for<br class="gmail_msg">decomposing strings?” &nbsp;It's, “what do you have to do with strings that's<br class="gmail_msg">hard in Swift *because* you can't index them with integers?”<br class="gmail_msg"></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div class="gmail_msg" style="word-wrap: break-word;"><div class="gmail_msg"><div class="gmail_msg">Hi Dave,</div><div class="gmail_msg">Ok. here are just a few examples:&nbsp;</div>Parsing and validating an ISBN code? or a (freight) container ID? or EAN13 perhaps?&nbsp;</div><div class="gmail_msg">of many of the typical combined article codes and product IDs that many factories and shops use?&nbsp;</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">or:&nbsp;</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">E.g. processing legacy files from IBM mainframes:</div><div class="gmail_msg">extract fields from ancient data records read from very old sequential files,</div><div class="gmail_msg">say, a product data record like this from a file from 1978 you’d have to unpack and process: &nbsp;&nbsp;</div><div class="gmail_msg">123534-09EVXD4568,991234,89ABCYELLOW12AGRAINESYTEMZ3453</div><div class="gmail_msg">into:</div><div class="gmail_msg">123, 534, -09, EVXD45, 68,99, 1234,99, ABC, YELLOW, 12A, GRAIN, ESYSTEM, Z3453.</div><div class="gmail_msg">product category, pcs, discount code, product code, price Yen, price $, class code, etc…&nbsp;</div><div class="gmail_msg">in Cobol and PL/1 records are nearly always defined with a fixed field layout like this.:</div><div class="gmail_msg">(storage was limited and very, very expensive, e.g. XML would be regarded as a&nbsp;</div><div class="gmail_msg">"scandalous waste" even the commas in CSV files! )&nbsp;</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">01 &nbsp;MAILING-RECORD.</div><pre class="gmail_msg"><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;COMPANY-NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PIC X(30).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;CONTACTS.</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp;PRESIDENT.</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;LAST-NAME &nbsp; &nbsp; &nbsp; PIC X(15).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;FIRST-NAME &nbsp; &nbsp; &nbsp;PIC X(8).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp;VP-MARKETING.</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;LAST-NAME &nbsp; &nbsp; &nbsp; PIC X(15).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;FIRST-NAME &nbsp; &nbsp; &nbsp;PIC X(8).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp;ALTERNATE-CONTACT.</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;TITLE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PIC X(10).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;LAST-NAME &nbsp; &nbsp; &nbsp; PIC X(15).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;FIRST-NAME &nbsp; &nbsp; &nbsp;PIC X(8).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;ADDRESS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PIC X(15).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;CITY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PIC X(15).</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;STATE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PIC XX.</div><div class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;ZIP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PIC 9(5).</div><div class="gmail_msg"><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">These are all character data fields here, except for the numeric ZIP field , however in Cobol it can be treated like character data.&nbsp;</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><div class="gmail_msg">So here I am, having to get the data of these old Cobol production files</div><div class="gmail_msg">into a brand new Swift based accounting system of 2017, what can I do? &nbsp;&nbsp;</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">How do I unpack these records and being the data into a Swift structure or class?&nbsp;</div><div class="gmail_msg">(In Cobol I don’t have to because of the predefined fixed format record layout).</div></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">AFAIK there are no similar record structures with fixed fields like this available Swift?</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">So, the only way I can think of right now is to do it like this:</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">// mailingRecord is a Swift structure</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">struct MailingRecord</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">{</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">&nbsp; &nbsp; var &nbsp;companyName: String = “no Name”</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">&nbsp; &nbsp; &nbsp;var contacts: CompanyContacts</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">&nbsp; &nbsp; &nbsp;.</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">&nbsp; &nbsp; &nbsp;etc..&nbsp;</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">}</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">// recordStr was read here with ASCII encoding</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">// unpack data in to structure’s properties, in this case all are Strings</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">mailingRecord.companyName &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = recordStr[ 0..&lt;30]</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">mailingRecord.contacts.president.lastName &nbsp;= recordStr[30..&lt;45]</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">mailingRecord.contacts.president.firstName = recordStr[45..&lt;53]</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">// and so on..</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">Ever worked for e.g. a bank with thousands of these files unchanged formats for years?</div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;"><br class="gmail_msg"></div><div class="gmail_msg" style="font-family: Avenir; white-space: normal;">Any alternative, convenient en simpler methods in Swift present?&nbsp;</div></div></pre></div></blockquote><div class="">These looks like examples of fix data format</div></div></div></div></blockquote><div class="">Hi Shawn,</div><div class="">No, it could also be an UTF-8 String.</div>&nbsp;&nbsp;<br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class="">that could be parsed from a byte buffer into strings, etc.<span class="Apple-converted-space">&nbsp;</span></div></div></div></div></blockquote><div class="">How would you do that? could you please provide an example how to do this, with a byte buffer?&nbsp;</div><div class="">eg. read from flat ascii file —&gt; unpack fields —&gt; store in structure props?&nbsp;</div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class="">Likely little need to force them via a higher order string concept,</div></div></div></div></blockquote><div class="">What do you mean here with “high order string concept” ??</div><div class="">Swift is a high level language, I expect to do this with Strings directly,</div><div class="">instead of being forced to use low-level coding with byte arrays etc.</div><div class="">(I have/want no time for that)</div><div class="">Surely, one doesn’t have to resort to that in a high level language like Swift?&nbsp;</div><div class="">If I am certain that all characters in a file etc. are of fixed width, even in UTF-32</div><div class="">(in the above example I am 100% sure of that) then&nbsp;</div><div class="">using &nbsp;str[n1..&lt;n2] is that case legitimate, because there are no</div><div class="">grapheme characters involved.</div><div class="">Therefore IMHO String direct subscripting should be available in Swift&nbsp;</div><div class="">for all Unicode types, and that the responsibility wether or not to use</div><div class="">this feature is with the programmer, not the language designer.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class="">at least not until unpacked from its compact byte form.</div></div></div></div></blockquote><div class="">I am sorry, but to me, it all sounds a bit like:</div><div class="">“why solve the problem with simple solution, when one can make it much</div><div class="">more complicated?” Be more pragmatic.</div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">TedvG,&nbsp;<br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class=""><br class=""></div><div class="">-Shawn&nbsp;<br class=""></div></div></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>