From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: how to parse words from a string
Date: Thu, 14 Nov 2002 08:56:25 -0600
Date: 2002-11-14T08:56:25-06:00 [thread overview]
Message-ID: <mailman.1037285822.25493.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: a04a773e.0211140540.5bcaa2ad@posting.google.com
----- Original Message -----
From: "Sarah Thomas" <mabes180@aol.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, November 14, 2002 7:40 AM
Subject: Re: how to parse words from a string
> Interesting follow ups! thanks for the input and help !
> I have succesfully extracted words from a string.
> I read each line in from the file
> and used find_token, followed by slice, followed by deleting the word
> from the string..and then stored them in a fixed array for now..
> this is just an outline of how i did it.....
>
> loop
> Find_Token(Temp, Ada.Strings.Maps.To_Set(Ada.Characters.Latin_1.HT),
> Ada.Strings.Outside, From, To);
> exit when To = 0;
>
> My_word := To_Unbounded_String(Slice(Temp, From, To));
> Put_line(Output_File,To_String(My_word));
>
> IF (Length(temp) /= To ) then
> Delete(Temp, 1, To + 1);
> else
> Delete(Temp, 1, To);
> end if;
>
> Store_data(Line_Number,Word_Number) := (My_Word);
>
> end loop;
You could have saved the work of repeatedly deleting from the
Temp string by initially setting To := Length (Temp) - 1;.
Then if you make your call to Find_Token like this:
Find_Token(Slice (Temp, To + 1, Length (Temp)),
Ada.Strings.Maps.To_Set(Ada.Characters.Latin_1.HT),
Ada.Strings.Outside, From, To);
you just specify the unprocessed slice of Temp each time you look for a new
token.
I'm sure you realize you could have declared a String of word delimiters to
include
spaces, punctuation marks and other white space characters in the set of
possible
word delimiters, and used that String to initialize a Word_Delimiter_Set --
e.g.:
Word_Delimiter_Set : constant Ada.Strings.Maps.Character_Set :=
Ada.Strings.Maps.To_Set
(" ,.;:/!&()" & Ada.Characters.Latin_1.HT & Ada.Characters.Latin_1.FF);
next prev parent reply other threads:[~2002-11-14 14:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-12 19:33 how to parse words from a string Sarah Thomas
2002-11-12 20:15 ` Stephen Leake
2002-11-12 20:16 ` Simon Wright
2002-11-13 10:17 ` Caffeine Junky
2002-11-14 2:10 ` Chad R. Meiners
2002-11-14 2:40 ` Caffeine Junky
2002-11-14 3:09 ` sk
2002-11-14 5:31 ` Dennis Lee Bieber
2002-11-14 13:40 ` Sarah Thomas
2002-11-14 14:56 ` David C. Hoos [this message]
2002-11-14 18:45 ` Jeffrey Carter
2002-11-17 8:40 ` Mário Amado Alves
2002-11-17 21:14 ` Jeffrey Carter
2002-11-18 11:00 ` Mário Amado Alves
2002-11-18 19:23 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox