From Xojo Documentation
Jump to: navigation, search

Use to convert the passed data type to a String. Numbers are formatted using the system settings for numerical display.



Part Type Description
result String The string representation of the value passed.
data Variant The variable that will be represented as a string.


You can pass a class instance as long as the class implements the Operator_Convert method that returns a String.

For real numbers, CStr returns 7 significant digits. When you pass a real number to CStr, the string it returns uses the decimal separator the user specified in system preferences. However, in most cases you will want to use the Format function instead for more precise control of the formatting. Use the Str function if you want to ensure US/English notation.

If you pass a Boolean, CStr will return either the string "True" or "False". If you pass a Color, it will return the hex representation of the color as a String. If you pass a Date, it will return the value of the date in SQL Date-time format.


These examples return the string representation of two numbers and a Boolean.

Dim s As String
Dim d As New Date
s = CStr(1) //returns "1", as a string
s = CStr(d.Day) //returns the day number as a string
s = CStr(True) //returns "True"

This example returns the approximation to Pi as a String to 7 significant digits.

Dim s As String
Const Pi = 3.14159265358979323846264338327950
s= CStr(pi) // returns "3.141593"

See Also

Format, CDbl, Str, Val functions; Boolean, Color, Date, String, Variant datatypes.

Personal tools

Starting Out
Dig Deeper
More Help