- 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
How to Trim a String in Arduino?
Sometimes, a string can contain leading or trailing whitespaces. Arduino has a trim() function that removes all these leading/trailing whitespaces from the string.
Syntax
String1.trim()
Where String1 is the string that you need to trim. Please note that this function doesn’t return anything. String1 itself is modified.
Example
The following example illustrates this −
void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); String string1 = " Hello World! "; Serial.println(string1); string1.trim(); Serial.println(string1); } void loop() { // put your main code here, to run repeatedly: }
Output
The Serial Monitor output is shown below −
As you can see, string1 was modified in place.
- Related Articles
- How to trim a string using $.trim() in jQuery?
- How to Trim a String in Golang?
- How to trim a string at beginning or ending in JavaScript?
- How to Remove Characters from a String in Arduino?
- How to trim a file extension from a string using JavaScript?
- How to trim down non printable characters from a string in Python?
- The correct way to trim a string in Java.
- String to byteArray in Arduino
- Golang Program to trim a string from both sides
- Python Program to trim a string from both sides
- Trim a string in Java to remove leading and trailing spaces
- Replace characters in a string in Arduino
- String comparisons in Arduino
- Trim and split string to form array in JavaScript
- Java String trim() method example.

Advertisements