I need a function to split sentence
Posted on 2007-10-10
I have a function that split my sentence in words
procedure SplitString (const Delimiter: Char; Input: string; const Strings: TStrings) ;
Strings.Delimiter := Delimiter;
Strings.DelimitedText := Input;
But I need something more clever, imagine a sentence like this:
Phr := "I am here working with my sister and she is working right now"
The procedure should work this way
procedure SplitSentence(Sentence: String, SplitNumber: Integer, const Strings: TStrings)
SplitNumber is the number words together, example:
SplitSentence(Phr, 2, List);
the sentence will be split in group of two words, something like this:
As you can see, the last word is odd, then as it is the last, it can be without any group.
I hope you understand what I need.