How to get smaller string from an unlimited string

I am having trouble reading inline from a file and then breaking into single words. Let's say I read "When the night was young" because that was the first line, I can't figure out how to just get the word "When" from the rest of it, I've tried many times, you're running out of ideas. I'm new to unlimited strings in Ada and just Ada in general. Any help is appreciated, small tips or solution to my problem, thanks.

with Ada.Text_IO;                   use Ada.Text_IO;
with Ada.Strings.Unbounded;         use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;

with AVL; use AVL;

procedure Spellchecker is
   InWord      : Unbounded_String;
   ReadIn      : String (1..20);
   Break       : Character := ' ';
   RevisedWord : String(1..20);
   Dictionary  : File_Type;
   Paragraph   : File_Type;
   Count       : Integer;
   LastChar    : Integer;
   NewTree     : Tree;

   type Spell is array (Integer range 1..20) of Character;
   Revision : Spell;

begin
   Ada.Text_IO.Open (File => Dictionary,
                     Mode => In_File,
                     Name => "dictionary.txt");
   loop
      exit when End_of_File (File => Dictionary);
      InWord := Get_Line (File => Dictionary);
      Insert (InWord, NewTree);
   end loop;
   Close (File => Dictionary);
   Print (NewTree);
   InWord := Get_Line (File => Paragraph);
   Count := 1;
   Put (InWord);
end Spellchecker;

      

+3


source to share


1 answer


There are at least two options:



  • You can convert Unbounded_String

    to regular fixed length String

    and work with that.
  • You can find subroutines Index

    and Slice

    in the section of the reference manual describing Ada.Strings.Unbounded

    , and use them to find whitespace and cut appropriately Unbounded_String

    .
+3


source







All Articles