跳轉至內容

Rexx 程式設計/Rexx 指南/字串比較

來自華夏公益教科書,開放的書籍,構建一個開放的世界

字串比較是基於詞典字串順序進行的

[編輯 | 編輯原始碼]

字串運算子基於詞典字串順序進行比較。在詞典順序中排在前面的字串具有比排在後面的字串更低的比較值。

支援的運算子

[編輯 | 編輯原始碼]

以下示例展示了使用比較運算子進行字串比較。

animal = 'dog'
if animal > 'cat' then
  say animal "is lexically higher than cat"

支援以下比較運算子

[編輯 | 編輯原始碼]
= 	Equal To
\= 	Not Equal To
< 	Less Than
> 	Greater Than
<= 	Less Than or Equal To
>= 	Greater Than or Equal To
\< 	Not Less Than
\> 	Not Greater Than
<> 	Not Equal To
>< 	Not Equal To

傳統的字串比較運算子會忽略開頭和結尾的空白字元

[編輯 | 編輯原始碼]

傳統的字串比較運算子在進行比較時會忽略開頭和結尾的空白字元。

'  ' =        /* 1 true,  string comparison  (stripped whitespace matches null value)  */
'ABC' = ' ABC ' /* 1 true,  string comparison  (leading and trailing whitespace ignored) */

嚴格比較

[編輯 | 編輯原始碼]

嚴格的比較運算子不會忽略開頭和結尾的空白字元,在進行嚴格比較時,這些空白字元也必須匹配。

'  ' ==        /* 0 false,  strict comparison  (the spaces will not match the null value)  */
'ABC' == ' ABC ' /* 0 false,  strict comparison  (leading and trailing whitespace causes mismatch) *# /
華夏公益教科書