How To Remove Characters From A String In Arduino? - Tutorialspoint

  • Home
  • Whiteboard
  • Online Compilers
  • Practice
  • Articles
  • AI Assistant
  • Jobs
  • Tools
  • Corporate Training
  • Courses
  • Certifications
Menu Categories Login
  • Switch theme
  • SQL
  • HTML
  • CSS
  • Javascript
  • Python
  • Java
  • C
  • C++
  • PHP
  • Scala
  • C#
  • Tailwind CSS
  • Node.js
  • MySQL
  • MongoDB
  • PL/SQL
  • Swift
  • Bootstrap
  • R
  • Machine Learning
  • Blockchain
  • Angular
  • React Native
  • Computer Fundamentals
  • Compiler Design
  • Operating System
  • Data Structure and Algorithms
  • Computer Network
  • DBMS
  • Excel
Technical Questions and Answers
  • 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
How to Remove Characters from a String in Arduino? ArduinoArduino BoardsArduino IDEArduino Programming Language

The remove function in Arduino helps you remove one or more characters from within a string.

Syntax

myString.remove(index, count)

Here, index refers to the index from where removal has to start. Note that indexing in Arduino starts with 0. Thus, within string "Hello", 'H' is at index 0, 'e' is at index 1, and so on.

The count argument is optional, and it specifies the number of characters to remove. If you don’t specify the count, then all characters starting from index till the end of the string will be removed. If you specify count as say, 3, then 3 characters starting from index position will be removed.

Example

void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    String s1 = "Mississippi";    String s2 = "Mississippi";    String s3 = "Mississippi";    Serial.println(s1);    Serial.println(s2);    Serial.println(s3);    Serial.println();    s1.remove(3,6); //Remove 6 characters starting from position 3    s2.remove(3); //Remove all characters starting from position 3    s3.remove(3,1); //Remove 1 character starting from position 3    Serial.println(s1);    Serial.println(s2);    Serial.println(s3); } void loop() {    // put your main code here, to run repeatedly: }

Output

The Serial Monitor output is shown below −

As you can see, the removal of characters happens exactly as described in the comments of the code.

Yash Sanghvi Yash Sanghvi Updated on: 2021-05-29T13:31:15+05:30

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started Print Page Previous Next Advertisements

Tag » Arduino Remove N