- 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 a punctuation mark in Arduino
Just like there is a function to check if a character is alphanumeric or not, there is another one to check if a character is a punctuation mark or not. The name of the function is isPunct(). It takes a character as an input and returns a Boolean: true if the given character is a punctuation mark.
Example
The following example demonstrates the use of this function −
void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); char c1 = 'a'; char c2 = ','; char c3 = '1'; char c4 = '$'; char c5 = '%'; if (isPunct(c1)) { Serial.println("c1 is a punctuation mark!"); } else { Serial.println("c1 is NOT a punctuation mark!"); } if (isPunct(c2)) { Serial.println("c2 is a punctuation mark!"); } else { Serial.println("c2 is NOT a punctuation mark!"); } if (isPunct(c3)) { Serial.println("c3 is a punctuation mark!"); } else { Serial.println("c3 is NOT a punctuation mark!"); } if (isPunct(c4)) { Serial.println("c4 is a punctuation mark!"); } else { Serial.println("c4 is NOT a punctuation mark!"); } if (isPunct(c5)) { Serial.println("c5 is a punctuation mark!"); } else { Serial.println("c5 is NOT a punctuation mark!"); } } void loop() { // put your main code here, to run repeatedly: }
Output
The Serial Monitor output is shown below −
While it is a bit unexpected, even characters like ‘$’ and ‘%’ have been recognized as punctuation marks by this function. It appears that this function treats all special characters as punctuation marks. You are encouraged to try other special characters with this function.
- Related Articles
- Check whether the specified Unicode character is a punctuation mark in C#
- Check if a character is alphanumeric in Arduino
- Check if a character is printable in Arduino
- Check if a character is Space/Whitespace in Arduino
- JavaScript - Find if string is a palindrome (Check for punctuation)
- C# Program to check if a character is a whitespace character
- Check if string begins with punctuation in JavaScript
- How to check if a character in a string is a letter in Python?
- How to check if a character is upper-case in Python?
- How to check if a given character is a number/letter in Java?
- Check whether the Unicode character is a separator character in C#
- How to check if first character in a cell is a letter or number in Excel?
- Check if the board is connected or not in Arduino IDE
- PHP program to check if a string has a special character
- Check if all occurrences of a character appear together in Python

Advertisements