如何在 Arduino 中使用 isControl()?


isControl() 函式用於判斷一個字元是否是控制字元。控制字元或不可列印字元 (NPC) 是字元集中的程式碼點(一個數字),不表示書面符號。ASCII 表中程式碼 32 以下的所有條目都是這種型別的。其中包括 '
'、'\t' 等字元。

語法

isControl 函式的語法如下 −

isControl(myChar)

其中 myChar 是要評估的字元。如果它是控制字元,此函式將返回 True,否則返回 False。

示例

以下示例說明如何使用此功能 −

void setup() {
   Serial.begin(9600);
   Serial.println();
   char c1 = 'a';
   char c2 = '
';    if (isControl(c1)) {       Serial.println("c1 is a control char");    } else {       Serial.println("c1 is NOT a control char");    }    if (isControl(c2)) {       Serial.println("c2 is a control char");    } else {       Serial.println("c2 is NOT a control char");    } } void loop() { }

輸出

序列監視器輸出如下所示 −

更新於: 24-Jul-2021

564 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始學習
廣告
© . All rights reserved.