Character Analysis,识别字符的种类,如:字母,ASCII,空白符,控制字符,数字,标点符号,大小写字母,十六进制数

检查字符是否是ASCII,大写字母,数字,或者标点符号
可使用的操作器:
- isAlphaNumeric()
这是文字和数字
- isAlpha()
这是字母
- isAscii()
这是ASCII
- isWhitespace()
这是空白符(包括空格,TAB和回车等)
- isControl()
这是控制字符
- isDigit()
这是数字位数
- isGraph()
这是无空格可打印的字符
- isLowerCase()
这是小写字母
- isPrintable()
这是可打印的
- isPunct()
这是标点符号
- isSpace()
这是空格字符
- isUpperCase()
这是大写字母
- isHexadecimalDigit()
这是有效的十六进制位数(即是 0 - 9, a - F, or A - F)

官方案例:

oid setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // send an intro:
  Serial.println("send any byte and I'll tell you everything I can about it");
  Serial.println();
}

void loop() {
  // get any incoming bytes:
  if (Serial.available() > 0) {
    int thisChar = Serial.read();

    // say what was sent:
    Serial.print("You sent me: \'");
    Serial.write(thisChar);
    Serial.print("\'  ASCII Value: ");
    Serial.println(thisChar);

    // analyze what was sent:
    if (isAlphaNumeric(thisChar)) {
      Serial.println("it's alphanumeric");
    }
    if (isAlpha(thisChar)) {
      Serial.println("it's alphabetic");
    }
    if (isAscii(thisChar)) {
      Serial.println("it's ASCII");
    }
    if (isWhitespace(thisChar)) {
      Serial.println("it's whitespace");
    }
    if (isControl(thisChar)) {
      Serial.println("it's a control character");
    }
    if (isDigit(thisChar)) {
      Serial.println("it's a numeric digit");
    }
    if (isGraph(thisChar)) {
      Serial.println("it's a printable character that's not whitespace");
    }
    if (isLowerCase(thisChar)) {
      Serial.println("it's lower case");
    }
    if (isPrintable(thisChar)) {
      Serial.println("it's printable");
    }
    if (isPunct(thisChar)) {
      Serial.println("it's punctuation");
    }
    if (isSpace(thisChar)) {
      Serial.println("it's a space character");
    }
    if (isUpperCase(thisChar)) {
      Serial.println("it's upper case");
    }
    if (isHexadecimalDigit(thisChar)) {
      Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)");
    }

    // add some space and ask for another byte:
    Serial.println();
    Serial.println("Give me another byte:");
    Serial.println();
  }
}

你可能感兴趣的:(Character Analysis,识别字符的种类,如:字母,ASCII,空白符,控制字符,数字,标点符号,大小写字母,十六进制数)