String.concat()

Description

Combine, ou "concatène" deux objets String en un seul nouvel objet String. La deuxième chaîne de caractère est accolée à la première, et le résultat est placé dans un nouvel objet String.

Syntaxe

string.concat(string2)

Paramètres

  • string et string2: deux variables de type String()

Valeurs Renvoyées

  • Un nouveau String qui est la combinaison des deux Strings de départs.

Exemple

// declare three strings: String stringOne, stringTwo, stringThree; void setup() { Serial.begin(9600); stringOne = String("stringThree = "); stringTwo = String("this string"); stringThree = String (); Serial.println("\n\nAdding strings together (concatenation):"); } void loop() { // adding a constant integer to a string: stringThree = stringOne + 123; Serial.println(stringThree); // prints "stringThree = 123" // adding a constant long interger to a string: stringThree = stringOne + 123456789; Serial.println(stringThree); // prints " You added 123456789" // adding a constant character to a string: stringThree = stringOne + 'A'; Serial.println(stringThree); // prints "You added A" // adding a constant string to a string: stringThree = stringOne + "abc"; Serial.println(stringThree); // prints "You added abc" stringThree = stringOne + stringTwo; Serial.println(stringThree); // prints "You added this string" // adding a variable integer to a string: int sensorValue = analogRead(A0); stringOne = "Sensor value: "; stringThree = stringOne + sensorValue; Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has // adding a variable long integer to a string: long currentTime = millis(); stringOne="millis() value: "; stringThree = stringOne + millis(); Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has // do nothing while true: while(true); }
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.