String.Trim
From Xojo Documentation
Method
Returns the string passed with either whitespaces or the characters passed removed from the beginning and ending of the string.
Syntax
result=stringVariable.Trim(Optional ParamArray Characters() As String)
Part | Type | Description |
---|---|---|
result | String | source with leading and trailing whitespaces removed. |
stringVariable | String | A string variable, a copy of which is returned with leading and trailing whitespaces removed. |
Characters() | String | An optional ParamArray of characters that will be trimmed instead of whitespaces. |
Notes
Unless specific characters are passed in, Trim trims whitespace characters as defined by unicode.
Examples
This example removes the whitespaces from either side of the string passed:
This example removes *, and % from the beginning and ending of the string passed:
Var source as String = "*Hello World%"
Var result as String = source.Trim("*", "%") // Returns "Hello World"
Var result as String = source.Trim("*", "%") // Returns "Hello World"
This example trims the div tags from an HTML string:
Var source As String = "<div>Hello World</div>"
Var result As String = source.Trim("<div>","</div>") // Returns "Hello World"
Var result As String = source.Trim("<div>","</div>") // Returns "Hello World"
See Also
String.TrimLeft, String.TrimRight functions and String type.