Octave 中提供了字元類別測試函數,這些函數類似 C 語言標準函式庫中的函數,但 Octave 所提供的函數可以接受字串陣列並傳回包含 0 或 1 的矩陣,1 代表在字串陣列中對應的字元測試結果為 true,0 則代表 false,例如:
isalpha ("!Q@WERT^Y&")
輸出為
ans = 0 1 0 1 1 1 1 0 1 0
isalnum (s)
isalnum(s) 判斷字串 s 是否為字母或數字。
isalpha (s) isletter (s)
判斷字串 s 是否為字母(letter)。
isascii (s)
isascii(s) 函數會判斷字串 s 是否為 ASCII 字元(ASCII 碼介於 0 至 127)。
iscntrl (s)
iscntrl(s) 函數會判斷字串 s 是否為控制字元(control character)。
isdigit (s)
isdigit(s) 函數會判斷字串 s 是否為數字(digit)。
isgraph (s)
isgraph(s) 函數會判斷字串 s 是否為可顯示字元(printable character,不包含空白字元)。
isletter (s)
isletter(s) 函數會判斷字串 s 是否為字母(letter)。
islower (s)
islower(s) 函數會判斷字串 s 是否為小寫字母。
isprint (s)
isprint(s) 函數會判斷字串 s 是否為可顯示字元(printable character,包含空白字元)。
ispunct (s)
ispunct(s) 函數會判斷字串 s 是否為 punctuation character。
isspace (s)
isspace(s) 函數會判斷字串 s 是否為空白(包含 space、 formfeed、 newline、 carriage return、 tab 與 vertical tab)。
isupper (s)
isupper(s) 函數會判斷字串 s 是否為大寫字母。
isxdigit (s)
isxdigit(s) 函數會判斷字串 s 是否為十六進位的數字(hexadecimal digit)。
isstrprop (str, pred)
isstrprop(str, pred) 函數可以測試字串 str 的屬性,參數 pred 可指定屬性,例如:
isstrprop ("abc123", "alpha")
輸出為
ans = 1 1 1 0 0 0
若 str 為一個巢狀陣列,則會以遞迴的方式對每個元素測試。以下是參數 pred 可用的選項:
"alpha":字母(letter)。"alnum"、"alphanum":字母或數字。"ascii":ASCII 字元(ASCII 碼介於 0 至 127)。"cntrl":控制字元(control character)。"digit":數字(digit)。"graph"、"graphic":可顯示字元(printable character,不包含空白字元)。"lower":小寫字母。"print":可顯示字元(printable character,包含空白字元)。"punct":punctuation character。"space"、"wspace":空白(包含 space、 formfeed、 newline、 carriage return、 tab 與 vertical tab)。"upper":大寫字母。"xdigit":十六進位的數字(hexadecimal digit)。