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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a0833bbed8752e1f,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews1.google.com!not-for-mail From: fmdf@tiscali.it (fabio de francesco) Newsgroups: comp.lang.ada Subject: variable lenght strings Date: 21 Oct 2004 10:52:55 -0700 Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 82.49.51.99 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1098381175 24213 127.0.0.1 (21 Oct 2004 17:52:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 21 Oct 2004 17:52:55 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:5590 Date: 2004-10-21T10:52:55-07:00 List-Id: Hi, while studying from "Ada as a 2nd Language" I am having some problem to cope with Strings (Fixed, Unbounded and Bounded) manipulation and especially with assigning between different types of them and with overall with input/output. 1) Is it possible to use Get_Line with Unbounded and/or Bounded Strings? 2) If not, how should user input be managed when lines length isn't known a priori? 3) I have to write a program that parses a file in which there are lines that have to be "tokenized". I didn't find any Find_Token() usage example on the Book so I wrote a little piece of code in order to understand the procedure workings on a fixed string (Line A) that simulates file input. Think that I am used with C function strtok() and I must say that Ada Find_Token is much more elegant and not destructive as strtok() is. Ok, please let me know if the following is the correct usage: with Ada.Text_IO, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps, Ada.Strings.Maps.Constants; use Ada.Text_IO, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps, Ada.Strings.Maps.Constants; procedure Tokenize is S : constant String := ".symbol HP = High_Pressure "; -- Line A F : Positive := S'First; L : Natural := S'Last; W : String( 1..30 ); begin loop Find_Token(S(F..L), Alphanumeric_Set or To_Set("_."), Inside, F, L); if L /= 0 then Put_Line( Positive'Image( F ) & ( L - F ) * ' ' & Natural'Image( L ) ); Move( S( F..L ), W ); Put_Line( ' ' & W ); F := L + 1; L := S'Last; else exit; end if; end loop; end Tokenize; Is it correct to check the "L" value as a condition to exit the loop? Thank you in advance for any help, Fabio De Francesco