如何从无界字符串中获取较小的字符串

时间:2017-04-09 18:25:35

标签: string ada words

我无法从文件中读取一行,然后将其分解为单个单词。让我们说我读“当夜晚很年轻”,因为这是第一行,我无法弄清楚如何只是得到“何时”这个词远离其余部分,我已经尝试了多次,而且我没有想法。我对Ada中的无限字符串很新,而且只是Ada。感谢任何帮助,很少提示或解决我的问题,谢谢。

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;

1 个答案:

答案 0 :(得分:3)

至少有两个选择:

  • 您可以将Unbounded_String转换为常规固定长度String并对其进行操作。
  • 您可以在参考手册中描述Index的部分中查找子程序SliceAda.Strings.Unbounded,并使用这些子程序查找空格并适当地剪切Unbounded_String
相关问题