Created
February 23, 2020 05:48
-
-
Save techzeero/f3731dec9981363e8af1c95ff2391b4d to your computer and use it in GitHub Desktop.
Arduino String Manipulation by Functions | https://techzeero.com/arduino-tutorials/arduino-string-functionality/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Arduino String Manipulation by Functions | |
For more details, visit: https://techzeero.com/arduino-tutorials/arduino-string-functionality/ | |
*/ | |
void setup() { | |
char str[] = "This is my string"; // create a string | |
char out_str[40]; // output from string functions placed here | |
int num; // general purpose integer | |
Serial.begin(9600); | |
// (1) print the string | |
Serial.println(str); | |
// (2) get the length of the string (excludes null terminator) | |
num = strlen(str); | |
Serial.print("String length is: "); | |
Serial.println(num); | |
// (3) get the length of the array (includes null terminator) | |
num = sizeof(str); // sizeof() is not a C string function | |
Serial.print("Size of the array: "); | |
Serial.println(num); | |
// (4) copy a string | |
strcpy(out_str, str); | |
Serial.println(out_str); | |
// (5) add a string to the end of a string (append) | |
strcat(out_str, " sketch."); | |
Serial.println(out_str); | |
num = strlen(out_str); | |
Serial.print("String length is: "); | |
Serial.println(num); | |
num = sizeof(out_str); | |
Serial.print("Size of the array out_str[]: "); | |
Serial.println(num); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment