String trim() Method



Returns a new string by removing all leading and trailing spaces. However, this method doesnt discard spaces between two strings.

Syntax

String.trim()

Return Type

Returns a string.

Example

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

It will produce the following output −.

hello 
hello world 
hello
dart_programming_string.htm
Advertisements