 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a character is Space/Whitespace in Arduino
The isSpace() and isWhitespace() functions can be used to check if a character is a space or, more specifically, a whitespace. Whitespace is a subset of space. While whitespace includes only space and horizontal tab (‘\t’), space includes form feed (‘\f’), new line (‘
’), carriage return (‘\r’) and even vertical tab (‘\v’).
Example
The following example demonstrates the usage of these functions −
void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    char c1 = 'a';    char c2 = ' ';    char c3 = '\t';    char c4 = '
';    if (isSpace(c1)) {       Serial.println("c1 is a Space!");    } else {       Serial.println("c1 is NOT a Space!");    }    if (isWhitespace(c1)) {       Serial.println("c1 is a Whitespace!");    } else {       Serial.println("c1 is NOT a Whitespace!");    }    Serial.println();    if (isSpace(c2)) {       Serial.println("c2 is a Space!");    } else {       Serial.println("c2 is NOT a Space!");    }    if (isWhitespace(c2)) {       Serial.println("c2 is a Whitespace!");    } else {       Serial.println("c2 is NOT a Whitespace!");    }    Serial.println();    if (isSpace(c3)) {       Serial.println("c3 is a Space!");    } else {       Serial.println("c3 is NOT a Space!");    }    if (isWhitespace(c3)) {       Serial.println("c3 is a Whitespace!");    } else {       Serial.println("c3 is NOT a Whitespace!");    }    Serial.println();    if (isSpace(c4)) {       Serial.println("c4 is a Space!");    } else {       Serial.println("c4 is NOT a Space!");    }    if (isWhitespace(c4)) {       Serial.println("c4 is a Whitespace!");    } else {       Serial.println("c4 is NOT a Whitespace!");    }    Serial.println(); } void loop() {    // put your main code here, to run repeatedly: }  Output
The Serial Monitor Output is −

As can be seen, while space and tab characters are considered as both a space and whitespace, new line character is considered as space only, and not whitespace. You are encouraged to try this function on other characters as well.
Advertisements
 