From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, WEIRD_QUOTING autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7fc767abbf17c947 X-Google-Attributes: gid103376,public From: david.c.hoos.sr@ada95.com Subject: Re: Parsing a line into strings Date: 1998/07/11 Message-ID: <6o6e34$bl$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 370360173 References: <35A3A199.D55C3153@oit.edu> Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Sat Jul 11 01:11:00 1998 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT) Date: 1998-07-11T00:00:00+00:00 List-Id: In article <35A3A199.D55C3153@oit.edu>, C N wrote: > Hi all, > > I've been looking for a comand in Ada that is equivilent to C's > "strtok" . So far - no luck. > I need to break up a line that is read in from a file with the strings > delimited by comas and spaces. > > If this command does'nt exhist, would anyone be willing to share a > chunk of code they've developed that performs this operation? > > Any and all responses are greatly appreaciated, > > -=Chris=- > > -=// "Even a blind squrrel finds a nut once in a while." \\=- > The program at the end of this message will parse the string submitted as the first command line argument into tokens delimited by any of the characters in the string submitted as the second command line argument, and print the tokens one at a time to the standard output. --- begin program source code ---- with Ada.Command_Line; with Ada.Strings.Fixed; with Ada.Strings.Maps; with Ada.Text_Io; procedure Tokenize is begin if Ada.Command_Line.Argument_Count /= 2 then Ada.Text_Io.Put_Line (Ada.Text_Io.Standard_Error, "USAGE:" & Ada.Command_Line.Command_Name & " "); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; declare The_String : constant String := Ada.Command_Line.Argument (1); The_Delimiters : constant Ada.Strings.Maps.Character_Set := Ada.Strings.Maps.To_Set (Ada.Command_Line.Argument(2)); First : Positive; -- Index of first character in token Last : Natural := 0; -- Index of last character in token (also used -- incremented by 1 -- as the starting point for next search). begin loop Ada.Strings.Fixed.Find_Token (Source => The_String (Last + 1 .. The_String'Last), Set => The_Delimiters, Test => Ada.Strings.Outside, First => First, Last => Last); exit when Last = 0; Ada.Text_Io.Put_Line ("Token => """ & The_String (First .. Last) & """"); end loop; end; end Tokenize; --- end program source code ---- -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum