<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="">Hi Ted,<div class=""><br class=""></div><div class="">Dave is on vacation next two weeks so this is a reply on behalf of both him and me:</div><div class=""><br class=""><div><div class=""><blockquote type="cite" class="">On Feb 12, 2017, at 10:17,&nbsp;"Ted F.A. van Gaalen" &lt;<a href="mailto:tedvgiosdev@gmail.com" class="">tedvgiosdev@gmail.com</a>&gt; wrote:</blockquote></div><div class=""><div dir="auto" class=""><blockquote type="cite" class=""><div class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On 11 Feb 2017, at 18:33, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">All of these examples should be efficiently and expressively handled by the pattern matching API mentioned in the proposal. They definitely do not require random access or integer indexing.&nbsp;<br class=""><br class=""></div></div></div></blockquote><div class="">Hi Dave,&nbsp;</div><div class="">then I am very interested to know how to unpack aString (e.g. read from a file record such as in the previous example:</div><div class="">123534-09EVXD4568,991234,89ABCYELLOW12AGRAINESYTEMZ3453 )&nbsp;</div><div class="">without using direct subscripting like str[n1…n2) ?&nbsp;</div></div></div></div></div></blockquote><div dir="auto" class=""><br class=""></div><div dir="auto" class="">If you look again at the code I sent previously, it demonstrates how you can use lengths to move forward through a string without needing random access for your particular use case.</div><div dir="auto" class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">(which btw is for me the most straightforward and ideal method)&nbsp;</div><div class="">conditions:</div><div class="">&nbsp; &nbsp;-The source string contains fields of known position (offset) and length, concatenated together</div><div class="">&nbsp; &nbsp; without any separators (like in a CSV)</div><div class="">&nbsp; -the &nbsp;contents of each field is unpredictable.&nbsp;</div><div class="">&nbsp; &nbsp;which excludes the use of pattern-matching.&nbsp;</div></div></div></div></div></blockquote><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Pattern matching isn’t just about matching known contents. Think of the regex “...”. This is a pattern matches any 3 characters. While full regex support is out of scope for the current discussions, the intention is for the pattern matching part of the proposal to handle this kind of use case.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">&nbsp; &nbsp;-the source string needs to be unpacked in independent strings.&nbsp;</div><div class=""><br class=""></div><div class="">I made this example: (the comments also stress my point)&nbsp;</div><div class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><div style="font-family: Menlo; font-size: 18px; margin: 0px; line-height: normal;" class=""><br class=""></div></div></div></div></div></div></div></blockquote><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><div dir="auto" class="">Here is another way of implementing your example in a form that doesn’t require random access.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Putting aside pattern matching for now, assume that there is an API on String that lets you drop a specific-length prefix from a Substring (for now in Swift 3, that's a String). An API like this (probably taking any pattern as its argument, not just a length) is likely to be proposed to evolution soon once we move into that phase of the 4.0 String project.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">// this particular API/implementation for demonstration only,</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">// not necessarily quite what will be proposed</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Collection</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> SubSequence == </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0); font-variant-ligatures: no-common-ligatures;" class="">/// Drop n elements from the front of `self` in-place,</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 128, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">/// returning the dropped prefix.</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">mutating</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> dropPrefix(</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> n: IndexDistance) -&gt; SubSequence {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// nature of error handling/swallowing/trapping/optional</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// returning here TBD...</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> newStart = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">index</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">startIndex</span><span style="font-variant-ligatures: no-common-ligatures" class="">, offsetBy: n)</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">defer</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">[newStart..&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">endIndex</span><span style="font-variant-ligatures: no-common-ligatures" class="">] }</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">startIndex</span><span style="font-variant-ligatures: no-common-ligatures" class="">..&lt;newStart]</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// soon...</span></div><div style="margin: 0px; line-height: normal; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">String</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures" class="">Collection</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> { }</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div></div></div></div><div dir="auto" class=""><div dir="auto" class="">Given this, here’s your example code written using it (compacted a little for brevity):</div></div><div dir="auto" class=""><br class=""></div><div dir="auto" 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: #0433ff" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Product {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> id, group, name, description, currency: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> inStock, ordered, price: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span></div><p 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"></p><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> priceFormatted: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> whole = (</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">price</span><span style="font-variant-ligatures: no-common-ligatures" class="">/100)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> cents = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">price</span><span style="font-variant-ligatures: no-common-ligatures" class=""> - (whole * 100)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">currency</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">+</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">" </span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">whole</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">).</span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">cents</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">)"</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><p 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"></p><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(inputrecord: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// note, no copying will occur here, as String is</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// copy-on-write and there’s no writing happening</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> record = inputrecord</span></div><p style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">id</span><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = &nbsp; &nbsp; record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(10)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">group</span><span style="font-variant-ligatures: no-common-ligatures" class=""> &nbsp; &nbsp; &nbsp; = &nbsp; &nbsp; record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(4)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">name</span><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; = &nbsp; &nbsp; record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(16)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">description</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = &nbsp; &nbsp; record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(30)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">inStock</span><span style="font-variant-ligatures: no-common-ligatures" class=""> &nbsp; &nbsp; = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">(record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(10))!</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">ordered</span><span style="font-variant-ligatures: no-common-ligatures" class=""> &nbsp; &nbsp; = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">(record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(10))!</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">price</span><span style="font-variant-ligatures: no-common-ligatures" class=""> &nbsp; &nbsp; &nbsp; = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">(record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(10))!</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">currency</span><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; = &nbsp; &nbsp; record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(1)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</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(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> record = </span><span style="font-variant-ligatures: no-common-ligatures" class="">"123A.534.CMCU3Arduino Due &nbsp; &nbsp; Arm 32-bit Micro controller.&nbsp; 000000034100000005680000002250$"</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> product = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Product</span><span style="font-variant-ligatures: no-common-ligatures" class="">(inputrecord: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">record</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: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"=== Product data for the item with ID: </span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">product</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">id</span><span style="font-variant-ligatures: no-common-ligatures" class="">) ===="</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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(52, 149, 175);" class="">print</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="">"group&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : </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="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">product</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">group</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" 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: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : </span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">product</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">name</span><span style="font-variant-ligatures: no-common-ligatures" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; line-height: normal; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">"description&nbsp; &nbsp; : </span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">product</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">description</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"items in stock : </span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">product</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">inStock</span><span style="font-variant-ligatures: no-common-ligatures" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"items ordered&nbsp; : </span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">product</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">ordered</span><span style="font-variant-ligatures: no-common-ligatures" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; line-height: normal; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">"price per item : </span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">product</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">priceFormatted</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"=========================================================“</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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: #000000" class=""><br class=""></span></div></div><div class="">Now, other use cases might not have such a straightforward solution. But for the example here, this approach ought to suffice, or be a starting point for similar cases needing error handling, skipped regions etc.</div><div class=""><br class=""></div></div><blockquote type="cite" class=""><div class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><div style="font-family: Menlo; font-size: 18px; margin: 0px; line-height: normal; min-height: 21px;" class=""><div class=""><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">Isn’t that an elegant solution or what?&nbsp;</div></div></div></div></div></div></div></div></div></blockquote><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Unfortunately not. Adding integer subscripting to String via an extension that uses index(_:offsetBy) is a commonly proposed idea that we strongly caution against. Strings use an opaque</div><div class="">index rather than integers for a reason, it’s not an oversight.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">The reason being: if ever your string contains more than just ASCII characters, then advancing a String's startIndex to the nth element becomes a linear-time operation, because Characters are variable length. As a result, every one of your uses of that subscript takes linear time. If you use them in a loop, then code that looks linear is actually (probably accidentally) quadratic.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Now, <i class="">sometimes</i>, when the String knows it only contains ASCII, it might be able to do the advance in constant time. But we still recommend against these kind of extensions to avoid performance pitfalls if ever you are handling strings where this isn’t the case. There are other techniques like the one shown above that achieve the same goal just as well.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><div style="font-family: Menlo; font-size: 18px; margin: 0px; line-height: normal; min-height: 21px;" class=""><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">I might start a very lengthy discussion here about the threshold of where and how</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">to protect the average programmer (like me :o) from falling in to language pittfalls</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">and to what extend these have effect on working with a PL. One cannot make</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">a PL idiot-proof. Of course, i agree a lot of it make sense, and also the “intelligence”</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">of the Swift compiler (sometimes it almost feels as if it sits next to me looking at</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">the screen and shaking its head from time to time) But hey, remember most of</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">us in our profession have a brain too.&nbsp;</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">(btw, if you now of a way to let Xcode respect in-between spaces when auto-formatting please let me know, thanks)</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class=""><br class=""></div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">@Ben Cohen:</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">Hi, you wrote:</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class=""><span style="font-family: Avenir-Medium;" class="">"p.s. as someone who has worked in a bank with thousands of ancient file formats, no argument from me that COBOL rules :)"</span></div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">Although still the most part of accounting software is Cobol (mostly because it is too expensive&nbsp;</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">and risky to convert to newer technologies) I don’t think that Cobol rules and that new apps definitely should</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">not be written in Cobol. I wouldn’t be doing Swift if I thought otherwise. &nbsp;</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">If I would be doing a Cobol project again, It would be with same enjoyment as say,</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">a 2017 mechanical engineer, working on a steam locomotive of a touristic railroad.</div></div></div></div></div></div></div></div></blockquote><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Indeed. It was in this nostalgic spirit that my comment was meant.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><div style="font-family: Menlo; font-size: 18px; margin: 0px; line-height: normal; min-height: 21px;" class=""><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">which I would do with dedication as well. However, never use this comparison</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">at the hiring interview..:o)</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class=""><br class=""></div></div></div></div></div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><div style="font-family: Menlo; font-size: 18px; margin: 0px; line-height: normal; min-height: 21px;" class=""><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class=""><br class=""></div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">Kind Regards</div><div style="font-family: Avenir; font-size: 14px; margin: 0px; line-height: normal; min-height: 21px;" class="">TedvG</div><div class=""><br class=""></div></div><div style="font-family: Menlo; font-size: 18px; margin: 0px; line-height: normal; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="font-family: Menlo; font-size: 18px; margin: 0px; line-height: normal; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="font-family: Menlo; font-size: 18px; margin: 0px; line-height: normal; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div></div></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><div class="">Sent from my moss-covered three-handled family gradunza</div></div><div class=""><br class="">On 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=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><br class=""><div class=""><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 class=""><br class=""></div><div class="">Hi Dave,</div><div class="">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="">of many of the typical combined article codes and product IDs that many factories and shops use?&nbsp;</div><div class=""><br class=""></div><div class="">or:&nbsp;</div><div class=""><br class=""></div><div class="">E.g. processing legacy files from IBM mainframes:</div><div class="">extract fields from ancient data records read from very old sequential files,</div><div class="">say, a product data record like this from a file from 1978 you’d have to unpack and process: &nbsp;&nbsp;</div><div class="">123534-09EVXD4568,991234,89ABCYELLOW12AGRAINESYTEMZ3453</div><div class="">into:</div><div class="">123, 534, -09, EVXD45, 68,99, 1234,99, ABC, YELLOW, 12A, GRAIN, ESYSTEM, Z3453.</div><div class="">product category, pcs, discount code, product code, price Yen, price $, class code, etc…&nbsp;</div><div class="">in Cobol and PL/1 records are nearly always defined with a fixed field layout like this.:</div><div class="">(storage was limited and very, very expensive, e.g. XML would be regarded as a&nbsp;</div><div class="">"scandalous waste" even the commas in CSV files! )&nbsp;</div><div class=""><br class=""></div><div class="">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;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">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=""><div class="">So here I am, having to get the data of these old Cobol production files</div><div class="">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;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">AFAIK there are no similar record structures with fixed fields like this available Swift?</div><div style="font-family: Avenir; white-space: normal;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">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=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">// mailingRecord is a Swift structure</div><div style="font-family: Avenir; white-space: normal;" class="">struct MailingRecord</div><div style="font-family: Avenir; white-space: normal;" class="">{</div><div style="font-family: Avenir; white-space: normal;" class="">&nbsp; &nbsp; var &nbsp;companyName: String = “no Name”</div><div style="font-family: Avenir; white-space: normal;" class="">&nbsp; &nbsp; &nbsp;var contacts: CompanyContacts</div><div style="font-family: Avenir; white-space: normal;" class="">&nbsp; &nbsp; &nbsp;.</div><div style="font-family: Avenir; white-space: normal;" class="">&nbsp; &nbsp; &nbsp;etc..&nbsp;</div><div style="font-family: Avenir; white-space: normal;" class="">}</div><div style="font-family: Avenir; white-space: normal;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">// recordStr was read here with ASCII encoding</div><div style="font-family: Avenir; white-space: normal;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">// unpack data in to structure’s properties, in this case all are Strings</div><div style="font-family: Avenir; white-space: normal;" class="">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="">mailingRecord.contacts.president.lastName &nbsp;= recordStr[30..&lt;45]</div><div style="font-family: Avenir; white-space: normal;" class="">mailingRecord.contacts.president.firstName = recordStr[45..&lt;53]</div><div style="font-family: Avenir; white-space: normal;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">// and so on..</div><div style="font-family: Avenir; white-space: normal;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">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=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">Any alternative, convenient en simpler methods in Swift present?&nbsp;</div><div style="font-family: Avenir; white-space: normal;" class=""><br class=""></div><div style="font-family: Avenir; white-space: normal;" class="">Kind Regards</div><div style="font-family: Avenir; white-space: normal;" class="">TedvG</div><div style="font-family: Avenir; white-space: normal;" class="">( example of the above Cobol record borrowed from here:&nbsp;</div><div class=""><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;" class=""><br class=""></div></div></pre><div class=""><br class=""></div><div class="">&nbsp; &nbsp;&nbsp;</div><div class=""><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=""></div></blockquote></div></div></blockquote></div><br class=""></div></div></div></blockquote></div></div></div><br class=""></div></body></html>