2017-04-09 36 views
3

我無法從文件中讀取一行,然後將其分解爲單個單詞。假設我讀過「當夜幕降臨時」,因爲那是第一行,我無法弄清楚如何讓「剩餘時間」這個詞消失,我已經嘗試過多次,已經沒有想法了。對於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

您可能會發現[此答案](http://stackoverflow.com/a/22857680/40851)有幫助。我知道它使用了一個GNAT特定的庫,但它分裂了。 –

回答

3

至少有兩個選項:

  • 您可以將Unbounded_String轉換爲常規固定長度String和上操作。
  • 您可以在描述Ada.Strings.Unbounded的參考手冊的章節中查找子程序IndexSlice,並使用它們查找空格並適當剪切Unbounded_String
相關問題