This function returns a new string with all leading and trailing white-space characters removed.
NOTE The following characters are white-space characters: space (" "), tab ("\t"), carriage return ("\r"), newline ("\n"), form feed ("\f") and vertical tab ("\v"). See White-space Characters for the full list, including Unicode characters.
string_trim(str);
| Argument | Type | Description |
|---|---|---|
| str | String | The string to trim |
clean_string = string_trim(" Text somewhere in the middle. ");
The above code calls the function string_trim on a string that contains both leading and trailing spaces. The result is assigned to a local variable named clean_string.
var _string_from_literal = @"
The first line
is followed by the second line
";
clean_string = string_trim(_string_literal);
The above code first defines a string literal that contains newlines by prefixing it with the @ character. It assigns the new string to the temporary variable _string_from_literal. This string is then trimmed using string_trim and the result is stored in a new variable clean_string.