wildzero
asked on
Split and then pair up a sentance
Hi there
Lets say I have a sentance like this
"My name is bob"
what I would like is a way to be able to get a list of the words like
my
name
is bob
and then get a list of all the words like
my name
name is
is bob
then again like
my name is
name is bob
Anyone have any suggestions?
=) Thanks guys!
Lets say I have a sentance like this
"My name is bob"
what I would like is a way to be able to get a list of the words like
my
name
is bob
and then get a list of all the words like
my name
name is
is bob
then again like
my name is
name is bob
Anyone have any suggestions?
=) Thanks guys!
ASKER
Check this out
Uses a Button, Listbox and a SPinEdit
var
SL : TStringlist;
i,b : integer;
sWords : String;
begin
SL := TStringlist.create;
Split(' ', Edit1.text, SL);
Listbox1.items.assign(SL);
For i := 0 to SL.count-1 do
Begin
sWords := '';
If (i + SpinEdit1.value) <= SL.Count then
begin
For b := 0 to SpinEdit1.Value-1 do
begin
If sWords = '' then
sWords := SL[i+b]
else
sWords := sWords + ' '+ SL[i+b];
end;
end;
ListBox1.Items.add(sWords) ;
End;
Uses a Button, Listbox and a SPinEdit
var
SL : TStringlist;
i,b : integer;
sWords : String;
begin
SL := TStringlist.create;
Split(' ', Edit1.text, SL);
Listbox1.items.assign(SL);
For i := 0 to SL.count-1 do
Begin
sWords := '';
If (i + SpinEdit1.value) <= SL.Count then
begin
For b := 0 to SpinEdit1.Value-1 do
begin
If sWords = '' then
sWords := SL[i+b]
else
sWords := sWords + ' '+ SL[i+b];
end;
end;
ListBox1.Items.add(sWords)
End;
ASKER
Anyone have any other suggestions on how I could improve the above function?
you say "words" but then use
my
name
"is bob"
should this be
my
name
is
bob
?
if so, I'll write something to do what you ask
my
name
"is bob"
should this be
my
name
is
bob
?
if so, I'll write something to do what you ask
ASKER
oh yea whops :P hehe
yea that should be right - didn't hit the enter key
See if you can improve on my code there
yea that should be right - didn't hit the enter key
See if you can improve on my code there
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you almost had it right actually :-)
ASKER
Thanks =)
ASKER
procedure Split(const Delimiter: Char; Input: string; const Strings: TStrings);
begin
Assert(Assigned(Strings));
Strings.Clear;
Strings.Delimiter := Delimiter;
Strings.DelimitedText := Input;
end;
used like
SL := TStringlist.create;
Split(' ', 'My name is bob', SL);
Now SL contains all the words line by line
how to tackle the next part?