std.algorithm.startsWith with maximal matching

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Jan 14 19:13:02 PST 2012


On Fri, Jan 13, 2012 at 09:30:35PM -0800, Jonathan M Davis wrote:
> On Friday, January 13, 2012 18:47:19 H. S. Teoh wrote:
[...]
> > But what I really want to accomplish is to parse a string containing
> > multiple words; at each point I have a list of permitted words that
> > need to be matched against the string; substring matches don't
> > count. I already have a way of skipping over spaces; so for medial
> > words, I can simulate this by appending a space to the end of the
> > word list passed to startsWith(). However, this doesn't work when
> > the word being matched is at the very end of the string, or if it is
> > followed by punctuation.
> > 
> > Is there another library function that can do this, or do I just
> > have to roll my own?
> 
> Use std.array.split. It will split a string into an array of strings
> using whitespace as the delimiter.
[...]

What about punctuation?


T

-- 
Don't modify spaghetti code unless you can eat the consequences.


More information about the Digitalmars-d-learn mailing list