Parse a String given some delimiters

Lodovico Giaretta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 30 16:16:52 PDT 2016


On Sunday, 30 October 2016 at 20:50:47 UTC, Alfred Newman wrote:
> Hello,
>
> I'm migrating some Python code to D, but I stuck at a dead 
> end...
>
> Sorry to provide some .py lines over here, but I got some 
> doubts about the best (fastest) way to do that in D.
>
> Executing the function parsertoken("_My   input.string", " 
> _,.", 2) will result "input".
> Parsercount("Dlang=-rocks!", " =-") will result 2,
>
> Thanks in advance

You can take inspiration from the following snippet:

=============================================
import std.stdio, std.regex;

void main()
{
	string s = "Hello.World !";
	auto ss = split(s, regex(`\.| `));
	ss.length.writeln;
	ss[1].writeln;
}
=============================================


More information about the Digitalmars-d-learn mailing list