Skip to content
Paul Squires edited this page Oct 19, 2026 · 2 revisions

Home › Converting Data Types › Str

Str

Returns a number or boolean as text.

Syntax

Declare Function Str ( ByVal n As Byte ) As String
Declare Function Str ( ByVal n As UByte ) As String
Declare Function Str ( ByVal n As Short ) As String
Declare Function Str ( ByVal n As UShort ) As String
Declare Function Str ( ByVal n As Long ) As String
Declare Function Str ( ByVal n As ULong ) As String
Declare Function Str ( ByVal n As LongInt ) As String
Declare Function Str ( ByVal n As ULongInt ) As String

Parameters

  • number
  • string

Description

Str converts numeric variables to their string representation. Used this way it is the String equivalent to WStr applied to numeric variables, and the opposite of the Val function, which converts a string into a number.

Str converts boolean variables to their string representation "false" / "true".

Str also converts Unicode character strings to ASCII character strings. Used this way it does the opposite of WStr. If an ASCII character string is given, that string is returned unmodified.

Remarks

Usage

result = Str[$]( number )

or

result = Str( string )

Dialect Differences

  • In the -lang qb dialect, Str will left pad a positive number with a space. 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).

Platform Differences

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

Differences from QB

  • QB does not support the wide-character string version of Str.

See also

Examples

Dim a As Integer

Dim b As String

a = 8421

b = Str(a)

Print a, b

Category: Converting Data Types
Kind: function


Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.

Clone this wiki locally