- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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.
- Related Articles
- C# Program to check if a character is a whitespace character
- Check if a character is alphanumeric in Arduino
- Check if a character is printable in Arduino
- Check if a character is a punctuation mark in Arduino
- Check if a String is whitespace, empty ("") or null in Java
- How to check if a string contains only whitespace letters in Python?
- Check if a string has white space in JavaScript?
- How to check if a character is upper-case in Python?
- Check if the board is connected or not in Arduino IDE
- How to check if a character in a string is a letter in Python?
- How to check if a given character is a number/letter in Java?
- Java Program to check whether the entered character a digit, white space, lower case or upper case character
- Check whether the Unicode character is a separator character in C#
- Check if two strings are equal or not in Arduino
- With JavaScript Regular Expression find a non-whitespace character.\n\n

Advertisements