Help Center›FreeBASIC
Trimfunction
Removes surrounding substrings or characters on the left and right side of a string
Syntax
Declare Function Trim ( ByRef str As Const String, [ Any ] ByRef trimset As Const String = " " ) As String
Declare Function Trim ( ByRef str As Const WString, [ Any ] ByRef trimset As Const WString = WStr(" ") ) As WString
Parameters
| Name | Description | |
|---|---|---|
str | The source string. | |
trimset | The substring to trim. |
Return value
Returns the trimmed string.
Description
This procedure trims surrounding characters from the left (beginning) and right (end) of a source string:
- Substrings matching
trimsetwill be trimmed if specified, otherwise spaces (ASCII code 32) are trimmed.
- If the
Anykeyword is used, any character matching a character intrimsetwill be trimmed.
Remarks
Usage
result = Trim[$]( str [, [ Any ] trimset ] )
Platform Differences
- DOS version/target of FreeBASIC does not support the wide-character version of
Trim.
Dialect Differences
- Not available in the -lang qb dialect unless referenced with the alias
__Trim.
- The string type suffix "$" is optional in the -lang fblite dialect.
- The string type suffix "$" is ignored in the -lang fb dialect, warn only with the -w suffix compile option (or -w pedantic compile option).
Differences from QB
- New to FreeBASIC
See also
Example
Dim s1 As String = " ... Stuck in the middle ... "
Print "'" + Trim(s1) + "'"
Print "'" + Trim(s1, Any " .") + "'"
Dim s2 As String = "BaaBaaaaB With You aaBBaaBaa"
Print "'" + Trim(s2, "Baa") + "'"
Print "'" + Trim(s2, Any "Ba") + "'"
will produce the output:
'... Stuck in the middle ...' 'Stuck in the middle' 'aaB With You aaB' ' With You '
Reference
- Documented in KeyPgTrim.html