- Rexx 教程
- Rexx - 首頁
- Rexx - 概述
- Rexx - 環境
- Rexx - 安裝
- Rexx - 外掛安裝
- Rexx - 基本語法
- Rexx - 資料型別
- Rexx - 變數
- Rexx - 運算子
- Rexx - 陣列
- Rexx - 迴圈
- Rexx - 決策
- Rexx - 數字
- Rexx - 字串
- Rexx - 函式
- Rexx - 棧
- Rexx - 檔案I/O
- Rexx - 檔案函式
- Rexx - 子程式
- Rexx - 內建函式
- Rexx - 系統命令
- Rexx - XML
- Rexx - Regina
- Rexx - 解析
- Rexx - 訊號
- Rexx - 除錯
- Rexx - 錯誤處理
- Rexx - 面向物件
- Rexx - 可移植性
- Rexx - 擴充套件函式
- Rexx - 指令
- Rexx - 實現
- Rexx - Netrexx
- Rexx - Brexx
- Rexx - 資料庫
- 手持式和嵌入式
- Rexx - 效能
- Rexx - 最佳程式設計實踐
- Rexx - 圖形使用者介面
- Rexx - Reginald
- Rexx - Web程式設計
- Rexx 有用資源
- Rexx - 快速指南
- Rexx - 有用資源
- Rexx - 討論
Rexx - 解析
Rexx 最強大的功能之一是其解析文字值的能力。您可能在其他任何程式語言中都看不到這一點。
parse 語句的通用格式如下:
語法
PARSE {UPPER|LOWER|CASELESS} source {template}
其中:
UPPER − 解析前將原始碼轉換為大寫。
LOWER − 解析前將原始碼轉換為小寫。
CASELESS − 傳遞此引數時,將忽略大小寫。
source − 這是需要解析的原始碼。為此提供了許多選項,可以是以下任何一個:
ARG − 程式或過程的引數可以用作原始碼。
LINEIN − 下一行輸入可以用作原始碼。
SOURCE − 程式的源資訊可以用作原始碼。
VAR name − 變數的值可以用作原始碼。
template − 此引數指定如何解析原始碼。為此提供了許多選項。下面列出了一些。
變數名 − 分配給變數的值。
字面字串 − 可用作分割字串的模式的字面字串。
# − 原始碼本身中的絕對字元位置。因此,如果您指定值為 5,則將使用第 5 個字元。
+# − 原始碼本身中的相對字元位置。因此,如果您指定值為 5,則將相對使用第 5 個字元。
讓我們來看一個在 Rexx 中如何完成解析的簡單示例。
示例
/* Main program */ parse value 'This is a Tutorial' with word1 word2 word3 word4 say "'"word1"'" say "'"word2"'" say "'"word3"'" say "'"word4"'"
上面的程式解析短語中的單詞。當一個值由僅以一個空格分隔的單片語成,並且沒有前導或尾隨空格時,該值很容易解析為已知數量的單詞,如下所示。
parse 函式用於在 Rexx 中獲取字串值,然後將其分解成單詞。在上面的示例中,單詞隨後被分割並存儲在單詞變數中。
上述程式的輸出如下:
'This' 'is' 'a' 'Tutorial'
以下程式顯示了另一個解析示例。這次我們使用 while 子句進行解析。
示例
/* Main program */ phrase = 'This is a Tutorial' do while phrase <> '' parse var phrase word phrase say "'"word"'" end
上述程式將給出以下輸出:
'This' 'is' 'a' 'Tutorial'
位置解析
Rexx 還允許使用位置解析。讓我們來看一個如何使用 parse 語句實現位置解析的示例。
示例
/* Main program */ testString = "Doe John M. 03/03/78 Mumbai India"; parse var testString name1 11 name2 21 birthday 31 town 51 country say name1 say name2 say birthday say town say country
從上面的示例中,您可以注意到,除了變數名外,我們還指定了字串應結束的位置。因此,對於 name1,我們應該在第 11 個字元處結束,然後開始解析 name2。
上述程式的輸出如下:
Doe John M. 03/03/78 Mumbai India
您也可以在這種情況下使用相對位置解析。
示例
/* Main program */ testString = "Doe John M. 03/03/78 Mumbai India"; parse var testString name1 +10 name2 +10 birthday +10 town +20 country say name1 say name2 say birthday say town say country
上述程式的輸出如下所示。
Doe John M. 03/03/78 Mumbai India