<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>One of the major (so far unstated) goals of the String rethink is to eliminate reasons for people to process textual data outside of String, though. You shouldn't have to use an array of bytes to get performance processing of ASCII, for example. &nbsp;<br><br><div>Sent from my moss-covered three-handled family gradunza</div></div><div><br>On Feb 9, 2017, at 6:56 PM, Shawn Erickson &lt;<a href="mailto:shawnce@gmail.com">shawnce@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 9, 2017 at 5:09 PM Ted F.A. van Gaalen &lt;<a href="mailto:tedvgiosdev@gmail.com">tedvgiosdev@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><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="m_-8685886003293606080Apple-interchange-newline gmail_msg"><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 style="word-wrap:break-word" class="gmail_msg"><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 style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">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 style="font-family:Avenir;white-space:normal" class="gmail_msg"><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 style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">AFAIK there are no similar record structures with fixed fields like this available Swift?</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">So, the only way I can think of right now is to do it like this:</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">// mailingRecord is a Swift structure</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">struct MailingRecord</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">{</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">&nbsp; &nbsp; var &nbsp;companyName: String = “no Name”</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">&nbsp; &nbsp; &nbsp;var contacts: CompanyContacts</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">&nbsp; &nbsp; &nbsp;.</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">&nbsp; &nbsp; &nbsp;etc..&nbsp;</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">}</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">// recordStr was read here with ASCII encoding</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">// unpack data in to structure’s properties, in this case all are Strings</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">mailingRecord.companyName &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = recordStr[ 0..&lt;30]</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">mailingRecord.contacts.president.lastName &nbsp;= recordStr[30..&lt;45]</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">mailingRecord.contacts.president.firstName = recordStr[45..&lt;53]</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">// and so on..</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">Ever worked for e.g. a bank with thousands of these files unchanged formats for years?</div><div style="font-family:Avenir;white-space:normal" class="gmail_msg"><br class="gmail_msg"></div><div style="font-family:Avenir;white-space:normal" class="gmail_msg">Any alternative, convenient en simpler methods in Swift present?&nbsp;</div></div></pre></div></blockquote><div>These looks like examples of fix data format that could be parsed from a byte buffer into strings, etc. Likely little need to force them via a higher order string concept, at least not until unpacked from its compact byte form.</div><div><br></div><div>-Shawn&nbsp;<br></div></div></div>
</div></blockquote></body></html>