Rexx - 行數



此函式返回 1 或輸入流中剩餘的行數。檔名作為函式的輸入給出。

語法

lines(filename)  

引數

  • filename − 這是檔名。

返回值

此函式返回 1 或輸入流中剩餘的行數。

示例

/* Main program */ 
do while lines(Example.txt) > 0 
   line_str = linein(Example.txt) 
   say line_str 
end  

在上面的程式中,需要注意以下幾點。

  • lines 函式讀取 Example.txt 檔案。

  • while 函式用於檢查 Example.txt 檔案中是否存在更多行。

  • 對於從檔案中讀取的每一行,line_str 變數都儲存當前行的值。然後將其傳送到控制檯作為輸出。

輸出 − 當我們執行上述程式時,我們將得到以下結果。

Example1 
Example2 
Example3

lines 命令還有另一種變體,如下所示:

語法

lines(filename,C)

引數

  • filename − 這是檔名。

  • C − 這是提供給函式的常數值。此值指定要從檔案中讀取的剩餘行數。

返回值

返回值是從檔案中剩餘要讀取的行數。

示例

/* Main program */ 
count = lines(Example.txt,C) 
say count 
line_str = linein(Example.txt) 

say line_str 
count = lines(Example.txt,C) 
say count 

當我們執行上述程式時,我們將得到以下結果。

輸出

3 
Example1 
2 
rexx_functions_for_files.htm
廣告

© . All rights reserved.