Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

I need a function to split sentence

Hello guys

I have a function that split my sentence in words

procedure SplitString (const Delimiter: Char; Input: string; const Strings: TStrings) ;
begin
 Assert(Assigned(Strings));
 Strings.Clear;
 Strings.Delimiter := Delimiter;
 Strings.DelimitedText := Input;
end;

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:

I am
here working
with my
sister and
she is
working right
now

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.
I thank
Alexandre


SOLUTION
Avatar of Johnjces
Johnjces
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Of course you can change the '3' to '2' or whatever'.

It has some issues in the last string depending upon the number of splits, but hopefully you get the idea.

John
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

If I put only one, the last word repeats, why?
Avatar of hidrau

ASKER

Cynna, it is perfect :))
very good

Johnjces, thanks for your support too , only the last word is being repeated. Take a look at it
Avatar of hidrau

ASKER

hello cynna

I remember you. You have made this function to me
https://www.experts-exchange.com/questions/22859109/Function-to-Find-word-in-richedit.html

I am having problem on it, when I try to find two our three words
can you see it for me? if you want I can open another thread.
thanks
Avatar of Cynna
Cynna

Hi hidrau from Brasil :-)

For the sake of completness, please go to original question (https://www.experts-exchange.com/questions/22859109/Function-to-Find-word-in-richedit.html)

And we'll continue there, OK?