Help Center
Help CenterFreeBASIC

RTrimfunction

Removes surrounding substrings or characters on the right side of a string

String Functionsfunctiondocumented

Syntax

Declare Function RTrim ( ByRef str As Const String, [ Any ] ByRef trimset As Const String = " " ) As String
Declare Function RTrim ( ByRef str As Const WString, [ Any ] ByRef trimset As Const WString = WStr(" ") ) As WString

Parameters

NameDescription
strThe source string.
trimsetThe substring to trim.

Return value


Returns the trimmed string.

Description


This procedure trims surrounding characters from the right (end) of a source string:
    • Substrings matching trimset will be trimmed if specified, otherwise spaces (ASCII code 32) are trimmed.
    • If the Any keyword is used, any character matching a character in trimset will be trimmed.
All comparisons are case-sensitive.

Remarks

Usage


result = RTrim[$]( str [, [ Any ] trimset ] )

Platform Differences


  • DOS version/target of FreeBASIC does not support the wide-character version of RTrim.

Dialect Differences


  • The string type suffix "$" is required in the -lang qb dialect.
  • 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


  • QB does not support specifying a trimset string or the ANY clause.

See also


Example


Dim s1 As String = "Article 101  "

Print "'" + RTrim(s1) + "'"

Print "'" + RTrim(s1, " 01") + "'"

Print "'" + RTrim(s1, Any " 10") + "'"



Dim s2 As String = "Test Pattern aaBBaaBaa"

Print "'" + RTrim(s2, "Baa") + "'"

Print "'" + RTrim(s2, Any "Ba") + "'"


will produce the output:

'Article 101'
'Article 101  '
'Article'
'Test Pattern aaB'
'Test Pattern '

Reference

  • Documented in KeyPgRtrim.html