<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 style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Avenir-Book" class="">Hi Ben,</font></span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Avenir-Book" class=""><br class=""></font></span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class="">In the case of processing all fields sequentially&nbsp;</span><span style="font-family: Avenir-Book;" class="">from a record, &nbsp;</span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class="">that are directly adjacent to each other</span><span style="font-family: Avenir-Book;" class="">, your method&nbsp;</span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class="">(tested on playground) is convenient, also because in this</span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" size="4" class="">case all I need to specify are the field’s lengths…</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" size="4" class="">It’s like slicing bread :o)&nbsp;</font></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class="">However, if one just wants to extract fields directly</span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class="">somewhere in the middle without having to deal</span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class="">with the other record's content it gets quite clumsy,</span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class="">Currently and AFAIK, no less than three&nbsp;</span><span style="font-family: Avenir-Book;" class="">statements are needed to do so:&nbsp;</span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><span style="font-family: Avenir-Book;" class="">&nbsp; var rec = record &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // create a mutable copy.</span></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><font face="Avenir-Book" class="">&nbsp; rec.dropPrefix(startpos) &nbsp;// ignore function result here</font></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><font face="Avenir-Book" class="">&nbsp; let result = rec.dropPrefix(length)&nbsp;</font></div><div style="margin: 0px; font-size: 18px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><font size="4" class="">(unless you know of a better way to do this? )&nbsp;</font></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><font size="4" class="">this is of course undesirable, so I’ve made a String extension</font></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><font size="4" class="">to do this</font></font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; font-size: 18px; font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">record</span><span style="font-family: Menlo; font-size: 18px; font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-family: Menlo; font-size: 18px; font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">midstr</span><span style="font-family: Menlo; font-size: 18px; font-variant-ligatures: no-common-ligatures;" class="">(at:&nbsp;pos</span><span style="font-family: Menlo; font-size: 18px; font-variant-ligatures: no-common-ligatures;" class="">, length:&nbsp;len</span><span style="font-family: Menlo; font-size: 18px; font-variant-ligatures: no-common-ligatures;" class="">)&nbsp;</span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><font size="4" class="">&nbsp;(see tested example below)&nbsp;</font></font></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="color: rgb(0, 132, 0); font-size: 18px; margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class="">( sidenote:&nbsp;</font></div><div style="color: rgb(0, 132, 0); font-size: 18px; margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>suggestion: imho dropPrefix should be three functions:</font></div><div style="margin: 0px; line-height: normal;" class=""><div style="color: rgb(0, 0, 0); font-size: 18px; margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class="">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space: pre;">        </span>- s2 = s1.getPrefix(len) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// which does not change s1 !!</font></div><div style="color: rgb(0, 0, 0); font-size: 18px;" class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class="">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space: pre;">        </span>-&nbsp;s2 = s1.getAndDropPrefix(len) // which also removes the prefix from s1.</font></div></div><div style="color: rgb(0, 0, 0); font-size: 18px; margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class="">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space: pre;">        </span>- s1.dropPrefix(len) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // which drops the prefix but does not return anything.</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><font size="4" class="">because at first sight intuitively one doesn’t expect that:</font></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><font size="4" class="">&nbsp; s1.dropPrefix(len) as it is now does in fact can optionally return the dropped part of s1..&nbsp;</font></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><font size="4" class="">&nbsp;in that case one could regard s2 = s1.dropPrefix(len) as a function having a side-effect,</font></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><font size="4" class="">which can be considered as bad programming practice...</font></font></div><div style="color: rgb(0, 0, 0); font-size: 18px; margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class="">).</font></div><div style="color: rgb(0, 0, 0); font-size: 18px; margin: 0px; line-height: normal;" class=""><font face="Avenir-Book" class=""><br class=""></font></div></div></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Avenir-Book" class=""><br class=""></font></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Avenir-Book" class=""><br class=""></font></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Avenir-Book" class="">see further in-line comments</font></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 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; font-family: Menlo; color: rgb(0, 132, 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; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Collection</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> SubSequence == </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">Self</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 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="">/// Drop n elements from the front of `self` in-place,</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 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; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">mutating</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> dropPrefix(</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> n: IndexDistance) -&gt; SubSequence {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 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; font-family: Menlo; color: rgb(0, 132, 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; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> newStart = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">index</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">startIndex</span><span style="font-variant-ligatures: no-common-ligatures" class="">, offsetBy: n)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">defer</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">[newStart..&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">endIndex</span><span style="font-variant-ligatures: no-common-ligatures" class="">] }</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">startIndex</span><span style="font-variant-ligatures: no-common-ligatures" class="">..&lt;newStart]</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// soon...</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// (TedvG) never depend on expectations such as "soon" :o)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" 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 style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Product</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" 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: #703daa" class="">String</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" 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: #703daa" class="">Int</span></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" 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; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> priceFormatted: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> whole = (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">price</span><span style="font-variant-ligatures: no-common-ligatures" class="">/</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">100</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> cents = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">price</span><span style="font-variant-ligatures: no-common-ligatures" class=""> - (whole * </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">100</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">currency</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">+</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">" </span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">whole</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">).</span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">cents</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">)"</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" 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; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(inputrecord: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 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; font-family: Menlo; color: rgb(0, 132, 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; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> record&nbsp; = inputrecord</span></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" 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; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">10</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">( </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">4</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">16</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">30</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">inStock</span><span style="font-variant-ligatures: no-common-ligatures" class=""> &nbsp; &nbsp; = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">(record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">10</span><span style="font-variant-ligatures: no-common-ligatures" class="">))!</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ordered</span><span style="font-variant-ligatures: no-common-ligatures" class=""> &nbsp; &nbsp; = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">(record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">10</span><span style="font-variant-ligatures: no-common-ligatures" class="">))!</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">(record.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">10</span><span style="font-variant-ligatures: no-common-ligatures" class="">))!</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">( </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" 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; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// var rec = record</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">//var descr = rec.dropPrefix(10 + 4 + 16).dropPrefix(30)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// does not work:</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Attempt to extract a substring with somewhere in the middle of the source</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// string with cascading in a single statement has failed</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// because&nbsp; dropPrefix(n) function's&nbsp; result is unmutable</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// pre-compiler diagnostic msg:</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// &nbsp; "Cannot use member on immutable value: function call returns immutable value."</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// (TedvG) I've made this string extension to allow direct substring access which</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// can be regarded as a work-around to provide for str[a..&lt;b] as yet not implemented.</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// (using midstr() instead of substr() in this playground example</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// to avoid confusion with existing substring functions.)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> midstr(at: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">, length:&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// error optionally throw...</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 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; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> s = </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// make a mutable copy of self (aString)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; s.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(at)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> s.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">dropPrefix</span><span style="font-variant-ligatures: no-common-ligatures" class="">(length)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> test()</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> product = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Product</span><span style="font-variant-ligatures: no-common-ligatures" class="">(inputrecord: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">record</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" 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: #000000" class="">product.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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: #000000" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">product.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">group</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; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" 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: #000000" class="">product.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" 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" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">product.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">description</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; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" 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 available: </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="">product.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" 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: #000000" class="">product.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" 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" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">product.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">priceFormatted</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; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" 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; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">// (TedvG) I've added this midstr. extension &nbsp;usage:&nbsp;</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);" class="">&nbsp; &nbsp; 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="">"=== Extracting substrings at random positions and length directly: =="</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">)</span></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" 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; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"description&nbsp; &nbsp; : </span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">record</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">midstr</span><span style="font-variant-ligatures: no-common-ligatures" class="">(at: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">30</span><span style="font-variant-ligatures: no-common-ligatures" class="">, length: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">30</span><span style="font-variant-ligatures: no-common-ligatures" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"items available: </span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">record</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">midstr</span><span style="font-variant-ligatures: no-common-ligatures" class="">(at: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">60</span><span style="font-variant-ligatures: no-common-ligatures" class="">, length: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">10</span><span style="font-variant-ligatures: no-common-ligatures" class="">))!</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">)."</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" 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; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"=====end of test.===================================================="</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">test</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">()</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">// test() prints this:</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">====== Product data for the item with ID: 123A.534.C ================</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">group&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : MCU3</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Arduino Due&nbsp; &nbsp; &nbsp;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">description&nbsp; &nbsp; : Arm 32-bit Micro controller. &nbsp;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">items available: 341</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">items ordered&nbsp; : 568</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">price per item : $ 22.50</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;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">=== Extracting substrings at random positions and length directly: ==</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">description&nbsp; &nbsp; : Arm 32-bit Micro controller. &nbsp;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">items available: 341.</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">=====end of test.====================================================</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div><blockquote type="cite" class=""><div class="">On 13 Feb 2017, at 02:49, Ben Cohen &lt;<a href="mailto:ben_cohen@apple.com" class="">ben_cohen@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 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></div></blockquote>Dave! if you are reading this now, you are not spending your vacation as it should be!</div><div>Put your iPhone away immediately, and resume sipping your&nbsp;<span style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255);" class="">piña colada! &nbsp;(&lt;- hey look Unicode! :o)</span><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><div class=""><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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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(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;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">String</span><span style="font-variant-ligatures: no-common-ligatures;" class="">: </span><span style="font-variant-ligatures: no-common-ligatures" class="">Collection</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> { }</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" 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><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;" 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><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;" 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;" 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;" 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><div 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"></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="">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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"items in stock : </span><span style="font-variant-ligatures: no-common-ligatures;" 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;" 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;" 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;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"items ordered&nbsp; : </span><span style="font-variant-ligatures: no-common-ligatures;" 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;" 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;" 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;" 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;" 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;" 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;" 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;" class="">(</span><span style="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;" 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></div></div></div></div></div></blockquote><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div class=""><div dir="auto" class=""><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></div></div></div></div></div></blockquote>Which could leave the impression that current string handling is badly designed/ structured?&nbsp;</div><div><br class=""></div><div>From an OOP &nbsp;point of view: I would expect each (Unicode) character to be (an object/instance of) a Unicode Character class,</div><div>which would imply that each element in aString would be (nothing more than) a reference to a single Character object..(in Swift a GraphemeCluster)&nbsp;</div><div>In that case, it would not make any difference at all, whether or not this Character object instance itself contains a single or more elements.</div><div>This method has its (perhaps optimisable) look-up performance drawbacks, but it would cancel out the performance drawbacks that are</div><div>(probably) caused by traversing aString sequentially at runtime each and every time you need a substring of it.. ?&nbsp;</div><div><br class=""></div><div>Before getting in to all this, &nbsp;(aarrrghh, how do I get out :o) I did assume that the str.character</div><div>had such independent behaviour, (has GraphemeClusters as direct accessible elements)&nbsp;</div><div>however that is not the case because it is (as it appears to me) a limited view upon String itself.&nbsp;</div><div><br class=""></div><div>Still, How things then &nbsp;should appear graphically on an output device &nbsp;(e.g. print positioning)</div><div>&nbsp;is then a matter for the displaying sub-system only, that’s were atomic GraphemeClusters are for, isn’t?</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div class=""><div dir="auto" class=""><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></div></div></div></div></div></blockquote>in the example given it is 100% certain that all String elements are ASCII.</div><div>How then, I might ask, can processing a row of just ASCII characters lead to performance pitfalls?</div><div><br class=""></div><div>Thanks,&nbsp;</div><div>Met vriendelijke groeten</div><div>TedvG</div><div><a href="http://www.tedvg.com" class="">www.tedvg.com</a></div><div><a href="http://www.ravelnotes.com" class="">www.ravelnotes.com</a></div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div class=""><div dir="auto" class=""><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></div></div></blockquote></div><br class=""></body></html>