How to get a substring?

Namespace rswhite4 at googlemail.com
Sat Oct 26 14:25:16 PDT 2013


On Saturday, 26 October 2013 at 21:23:13 UTC, Gautam Goel wrote:
> Dumb Newbie Question: I've searched through the library 
> reference, but I haven't figured out how to extract a substring 
> from a string. I'd like something like 
> string.substring("Hello", 0, 2) to return "Hel", for example. 
> What method am I looking for? Thanks!

Use slices:

string msg = "Hello";
string sub = msg[0 .. 2];


More information about the Digitalmars-d-learn mailing list