
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Find if a string begins with a specific set of characters in Arduino
The startsWith() function in Arduino helps you determine if a string starts with a specific set of characters. It returns true if the string starts with the substring you specified, else it returns false. An example implementation is given below −
Example
void setup() { // put your setup code here, to run once: Serial.begin(9600); String String1 = "AB_Test"; String String2 = "CD_Test"; String substr1 = "AB"; String substr2 = "AB*"; if(String1.startsWith(substr1)){ Serial.print("String1 starts with substr1"); } if(String2.startsWith(substr1)){ Serial.print("String2 starts with substr1"); } if(String1.startsWith(substr2)){ Serial.print("String1 starts with substr2"); } if(String2.startsWith(substr2)){ Serial.print("String2 starts with substr2"); } } void loop() { // put your main code here, to run repeatedly }
As you can expect, this program will print "String1 starts with substr1" only. The corresponding Serial Monitor output is shown below (the garbage characters in the beginning are programming/ start-up noise) −
Output
- Related Questions & Answers
- Set characters at a specific position within the string in Arduino
- How to check if the string begins with specific substring in Java?
- Clear/Set a specific bit of a number in Arduino
- Check if string begins with punctuation in JavaScript
- Replace characters in a string in Arduino
- Find if a substring exists within a string in Arduino
- Read a specific bit of a number with Arduino
- Search for specific characters within a string with MySQL?
- PHP fetch a specific value that begins with a given number from a string with letters and numbers?
- How to Remove Characters from a String in Arduino?
- MySQL query to select a specific string with special characters
- How to find MongoDB documents with a specific string?
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- How to remove specific characters from a string in Python?
- How to scan a string for specific characters in Python?
Advertisements