How to get a substring?

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sat Oct 26 16:49:26 PDT 2013


On Saturday, 26 October 2013 at 22:17:33 UTC, Ali Çehreli wrote:
>> Use slices:
>>
>> string msg = "Hello";
>> string sub = msg[0 .. 2];
>
> Yes but that works only if the string is known to contain only 
> ASCII codes. (Otherwise, a string is a collection of UTF-8 code 
> units.)

But that isn't how substring works. At least it seams neither 
Java or C# take UTF-8 encoding into account (as expected).

Though D generally has much better functions for some situations, 
find/until/countUntil/startsWith.


More information about the Digitalmars-d-learn mailing list