String trim (), méthode

Renvoie une nouvelle chaîne en supprimant tous les espaces de début et de fin. Cependant, cette méthode ne supprime pas les espaces entre deux chaînes.

Syntaxe

String.trim()

Type de retour

Renvoie une chaîne.

Exemple

void main() { 
   String str1 = "hello"; 
   String str2 = "hello world"; 
   String str3 = "hello"; 
   
   print(str1.trim()); 
   print(str2.trim()); 
   print(str3.trim()); 
}

Il produira ce qui suit output -.

hello 
hello world 
hello