Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))

Str Function

Class

Microsoft.VisualBasic.Conversion

Syntax

Dim result As String = Str(number)

number (required; Object)

Any valid numeric expression or an expression that can be converted to a number

Description

The Str function converts number from a number to a string.

Usage at a Glance

  • If number cannot be converted to a string, a runtime error occurs. To prevent this, check number with the IsNumeric function first.

  • If the return value is positive, the Str function always includes a leading space in the returned string for the sign of number.

  • Use the LTrim function to remove the leading space that the Str function adds to the start of the returned string.

  • The CStr and Format functions are often a better choice than the Str function. The CStr function does not add a leading space for the sign of a positive number. Both the CStr and the Format functions are internationally aware, recognizing locale-specific decimal delimiters.

See Also

CStr Function, Format Function

Категории