<div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Sep 6, 2018 at 4:45 PM Dukc via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thursday, 6 September 2018 at 14:17:28 UTC, aliak wrote:<br>
> // D<br>
> auto a = "á";<br>
> auto b = "á";<br>
> auto c = "\u200B";<br>
> auto x = a ~ c ~ a;<br>
> auto y = b ~ c ~ b;<br>
><br>
> writeln(a.length); // 2 wtf<br>
> writeln(b.length); // 3 wtf<br>
> writeln(x.length); // 7 wtf<br>
> writeln(y.length); // 9 wtf<br>
><br>
> writeln(a == b); // false wtf<br>
> writeln("ááááááá".canFind("á")); // false wtf<br>
><br>
<br>
I had to copy-paste that because I wondered how the last two can <br>
be false. They are because á is encoded differently. if you <br>
replace all occurences of it with a grapheme that fits to one <br>
code point, the results are:<br>
<br>
2<br>
2<br>
7<br>
7<br>
true<br>
true<br></blockquote><div><br></div><div>import std.stdio;</div><div>import std.algorithm : canFind;</div><div>import std.uni : normalize;</div><div><br></div><div>void main()</div><div>{</div><div>    auto a = "á".normalize;</div><div>    auto b = "á".normalize;</div><div>    auto c = "\u200B".normalize;</div><div>    auto x = a ~ c ~ a;</div><div>    auto y = b ~ c ~ b;</div><div>    </div><div>    writeln(a.length); // 2</div><div>    writeln(b.length); // 2</div><div>    writeln(x.length); // 7</div><div>    writeln(y.length); // 7</div><div><br></div><div>    writeln(a == b); // true</div><div>    writeln("ááááááá".canFind("á".normalize)); // true</div><div>} </div></div></div></div>