<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On 10 Feb 2017, at 00:11, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Thu Feb 09 2017, "Ted F.A. van Gaalen" &lt;<a href="http://tedvgiosdev-AT-gmail.com" class="">tedvgiosdev-AT-gmail.com</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">Hello Shawn<br class="">Just google with any programming language name and “string manipulation”<br class="">and you have enough reading for a week or so :o)<br class="">TedvG<br class=""></blockquote><br class="">That truly doesn't answer the question. &nbsp;It's not, “why do people index<br class="">strings with integers when that's the only tool they are given for<br class="">decomposing strings?” &nbsp;It's, “what do you have to do with strings that's<br class="">hard in Swift *because* you can't index them with integers?”<br class=""></div></div></blockquote><div><br class=""></div><div>Hi Dave,</div><div>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>of many of the typical combined article codes and product IDs that many factories and shops use?&nbsp;</div><div><br class=""></div><div>or:&nbsp;</div><div><br class=""></div><div>E.g. processing legacy files from IBM mainframes:</div><div>extract fields from ancient data records read from very old sequential files,</div><div>say, a product data record like this from a file from 1978 you’d have to unpack and process: &nbsp;&nbsp;</div><div>123534-09EVXD4568,991234,89ABCYELLOW12AGRAINESYTEMZ3453</div><div>into:</div><div>123, 534, -09, EVXD45, 68,99, 1234,99, ABC, YELLOW, 12A, GRAIN, ESYSTEM, Z3453.</div><div>product category, pcs, discount code, product code, price Yen, price $, class code, etc…&nbsp;</div><div>in Cobol and PL/1 records are nearly always defined with a fixed field layout like this.:</div><div>(storage was limited and very, very expensive, e.g. XML would be regarded as a&nbsp;</div><div>"scandalous waste" even the commas in CSV files! )&nbsp;</div><div><br class=""></div><div>01 &nbsp;MAILING-RECORD.</div><pre class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;COMPANY-NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PIC X(30).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;CONTACTS.</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp;PRESIDENT.</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;LAST-NAME &nbsp; &nbsp; &nbsp; PIC X(15).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;FIRST-NAME &nbsp; &nbsp; &nbsp;PIC X(8).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp;VP-MARKETING.</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;LAST-NAME &nbsp; &nbsp; &nbsp; PIC X(15).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;FIRST-NAME &nbsp; &nbsp; &nbsp;PIC X(8).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp;ALTERNATE-CONTACT.</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;TITLE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PIC X(10).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;LAST-NAME &nbsp; &nbsp; &nbsp; PIC X(15).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 &nbsp;FIRST-NAME &nbsp; &nbsp; &nbsp;PIC X(8).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;ADDRESS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PIC X(15).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;CITY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PIC X(15).</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;STATE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PIC XX.</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;05 &nbsp;ZIP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PIC 9(5).</div><div class=""><div style="font-family: Avenir; white-space: normal;"><br class=""></div><div 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 style="font-family: Avenir; white-space: normal;"><div>So here I am, having to get the data of these old Cobol production files</div><div>into a brand new Swift based accounting system of 2017, what can I do? &nbsp;&nbsp;</div><div class=""><br class=""></div><div class="">How do I unpack these records and being the data into a Swift structure or class?&nbsp;</div><div class="">(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;"><br class=""></div><div style="font-family: Avenir; white-space: normal;">AFAIK there are no similar record structures with fixed fields like this available Swift?</div><div style="font-family: Avenir; white-space: normal;"><br class=""></div><div 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 style="font-family: Avenir; white-space: normal;"><br class=""></div><div style="font-family: Avenir; white-space: normal;">// mailingRecord is a Swift structure</div><div style="font-family: Avenir; white-space: normal;">struct MailingRecord</div><div style="font-family: Avenir; white-space: normal;">{</div><div style="font-family: Avenir; white-space: normal;">&nbsp; &nbsp; var &nbsp;companyName: String = “no Name”</div><div style="font-family: Avenir; white-space: normal;">&nbsp; &nbsp; &nbsp;var contacts: CompanyContacts</div><div style="font-family: Avenir; white-space: normal;">&nbsp; &nbsp; &nbsp;.</div><div style="font-family: Avenir; white-space: normal;">&nbsp; &nbsp; &nbsp;etc..&nbsp;</div><div style="font-family: Avenir; white-space: normal;">}</div><div style="font-family: Avenir; white-space: normal;"><br class=""></div><div style="font-family: Avenir; white-space: normal;">// recordStr was read here with ASCII encoding</div><div style="font-family: Avenir; white-space: normal;"><br class=""></div><div style="font-family: Avenir; white-space: normal;">// unpack data in to structure’s properties, in this case all are Strings</div><div 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 style="font-family: Avenir; white-space: normal;">mailingRecord.contacts.president.lastName &nbsp;= recordStr[30..&lt;45]</div><div style="font-family: Avenir; white-space: normal;">mailingRecord.contacts.president.firstName = recordStr[45..&lt;53]</div><div style="font-family: Avenir; white-space: normal;"><br class=""></div><div style="font-family: Avenir; white-space: normal;"><br class=""></div><div style="font-family: Avenir; white-space: normal;">// and so on..</div><div style="font-family: Avenir; white-space: normal;"><br class=""></div><div 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 style="font-family: Avenir; white-space: normal;"><br class=""></div><div style="font-family: Avenir; white-space: normal;">Any alternative, convenient en simpler methods in Swift present?&nbsp;</div><div style="font-family: Avenir; white-space: normal;"><br class=""></div><div style="font-family: Avenir; white-space: normal;">Kind Regards</div><div style="font-family: Avenir; white-space: normal;">TedvG</div><div style="font-family: Avenir; white-space: normal;">( example of the above Cobol record borrowed from here:&nbsp;</div><div><font face="Avenir" class=""><span style="white-space: normal;" class="">&nbsp;<a href="http://www.3480-3590-data-conversion.com/article-reading-cobol-layouts-1.html" class="">http://www.3480-3590-data-conversion.com/article-reading-cobol-layouts-1.html</a>&nbsp; )&nbsp;</span></font></div><div style="font-family: Avenir; white-space: normal;"><br class=""></div></div></pre><div><br class=""></div><div>&nbsp; &nbsp;&nbsp;</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On 9 Feb 2017, at 16:48, Shawn Erickson &lt;<a href="mailto:shawnce@gmail.com" class="">shawnce@gmail.com</a>&gt; wrote:<br class=""><br class="">I also wonder what folks are actually doing that require indexing<br class="">into strings. I would love to see some real world examples of what<br class="">and why indexing into a string is needed. Who is the end consumer of<br class="">that string, etc.<br class=""><br class="">Do folks have so examples?<br class=""><br class="">-Shawn<br class=""><br class="">On Thu, Feb 9, 2017 at 6:56 AM Ted F.A. van Gaalen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;&gt; wrote:<br class="">Hello Hooman<br class="">That invalidates my assumptions, thanks for evaluating<br class="">it's more complex than I thought.<br class="">Kind Regards<br class="">Ted<br class=""><br class=""><blockquote type="cite" class="">On 8 Feb 2017, at 00:07, Hooman Mehr &lt;<a href="mailto:hooman@mac.com" class="">hooman@mac.com</a> &lt;<a href="mailto:hooman@mac.com" class="">mailto:hooman@mac.com</a>&gt;&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Feb 7, 2017, at 12:19 PM, Ted F.A. van Gaalen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;&gt; wrote:<br class=""><br class="">I now assume that:<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1. -= a “plain” Unicode character (codepoint?) &nbsp;can result in one glyph.=-<br class=""></blockquote><br class="">What do you mean by “plain”? Characters in some Unicode scripts are<br class="">by no means “plain”. They can affect (and be affected by) the<br class="">characters around them, they can cause glyphs around them to<br class="">rearrange or combine (like ligatures) or their visual<br class="">representation (glyph) may float in the same space as an adjacent<br class="">glyph (and seem to be part of the “host” glyph), etc. So, the<br class="">general relationship of a character and its corresponding glyph (if<br class="">there is one) is complex and depends on context and surroundings<br class="">characters.<br class=""><br class=""><blockquote type="cite" class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2. -= a &nbsp;grapheme cluster always results in just a single glyph, true? =- <br class=""></blockquote><br class="">False<br class=""><br class=""><blockquote type="cite" class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3. The only thing that I can see on screen or print are glyphs (“carvings”,visual elements that stand on their own )<br class=""></blockquote><br class="">The visible effect might not be a visual shape. It may be for example, the way the surrounding shapes change or re-arrange.<br class=""><br class=""><blockquote type="cite" class=""> &nbsp;&nbsp;&nbsp;&nbsp;4. &nbsp;In this context, a glyph is a humanly recognisable visual form of a character,<br class=""></blockquote><br class="">Not in a straightforward one to one fashion, not even in Latin / Roman script.<br class=""><br class=""><blockquote type="cite" class=""> &nbsp;&nbsp;&nbsp;&nbsp;5. On this level (the glyph, what I can see as a user) it is not relevant and also not detectable<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with how many Unicode scalars (codepoints ?), grapheme, or even on what kind<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of encoding the glyph was based upon.<br class=""></blockquote><br class="">False<br class=""><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;<br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote>&lt;<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>&gt;<br class=""><br class=""></blockquote><br class="">-- <br class="">-Dave<br class=""></div></div></blockquote></div><br class=""></body></html>