Difference between revisions of "TOSTRING()"

From Recital Documentation Wiki
Jump to: navigation, search
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{YLM to do}}
 
==Class==
 
Objects
 
 
 
 
==Purpose==
 
==Purpose==
Function to add a property to an existing object
+
Function to evaluate an expression and return the result as a string
  
  
 
==Syntax==
 
==Syntax==
ADDPROPERTY(<object-name> ,<expC>[,<exp>])
+
TOSTRING(<expr> [, <expN>])
  
  
 
==See Also==
 
==See Also==
[[ACLASS()]], [[ADDPROPERTY()]], [[AMEMBERS()]], [[CLASS]], [[CLONE()]], [[COMPOBJ()]], [[CREATEOBJECT()]], [[DEFINE CLASS]], [[DODEFAULT()]], [[METHOD]], [[NEWOBJECT()]], [[REMOVEPROPERTY()]], [[SET CLASSLIBRARY]], [[WITH]]
+
[[CAST()]], [[DTOC()]], [[DTOS()]], [[ETOS()]], [[LTOS()]], [[MTOS()]], [[RTOS()]], [[SET STRICT]], [[STR()]]
  
  
 
==Description==
 
==Description==
The Visual FoxPro compatible ADDPROPERTY() function is used to add a property to an existing objectIt returns .T. (True) if the property was successfully added and .F. (False) otherwise.
+
The TOSTRING() function evaluates the expression in <expr> and returns the result as a stringThe <expr> can be any valid string, date, datetime, logical or numeric expression.
  
 +
Where <expr> is a date or datetime expression, the string returned will conform to the current SET DATE, SET SEPARATOR, SET SECONDS and SET CENTURY settings, in the same format as DTOC() or TTOC().
  
{| class="wikitable"
+
The optional <expN> is used to specify the length of the string returnedIf the length is shorter than that required by <expr>, strings, dates and datetimes are truncated to the right and numerics truncated to the left.
!Parameter||Description
+
|-
+
|<object-name>||The name of the object.
+
|-
+
|<expC>||The name of the property to be added.
+
|-
+
|<exp>||The value to assign to the property being addedThis is optional: if omitted and the property being added already exists, the property value is unchanged, if omitted and the property is new, the value is initialized to .F. (False).
+
|-
+
|}
+
  
  
Properties can be removed using the REMOVEPROPERTY() function.
+
==Example==
 +
<code lang="recital">
 +
? tostring({03/29/2003})
 +
03/29/2003
 +
? tostring({03/29/2003},5)
 +
03/29
  
All classes have an inbuilt ADDPROPERTY 'factory method'.  This can be used as an alternative to the ADDPROPERTY() function to add properties to an object at runtime.
+
? tostring(10 * 10)
 +
      100
 +
? tostring(0.45,3)
 +
.45
  
 +
? tostring("Hello" + " " + "World")
 +
Hello World
 +
? tostring("Hello" + " " + "World",5)
 +
Hello
  
==Example==
+
? tostring(.F.)
<code lang="recital">
+
F
define class myclass as custom
+
myprop = "Hello World"
+
enddefine
+
 
+
myobject = createobject("myclass")
+
Messagebox(myobject.myprop)
+
addproperty(myobject, "myprop2", "goodbye")
+
// Or: myobject.addproperty("myprop2", "goodbye")
+
Messagebox(myobject.myprop2)
+
removeproperty(myobject, "myprop2")
+
 
</code>
 
</code>
  
  
 
==Products==
 
==Products==
Recital Database Server, Recital Mirage Server, Recital Terminal Developer
+
Recital, Recital Server
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
[[Category:Objects]]
+
[[Category:Expressions and Type Conversion]]
[[Category:Objects Functions]]
+
[[Category:Expressions and Type Conversion Functions]]
 +
[[Category:String Data]]
 +
[[Category:String Data Functions]]

Latest revision as of 15:52, 2 December 2009

Purpose

Function to evaluate an expression and return the result as a string


Syntax

TOSTRING(<expr> [, <expN>])


See Also

CAST(), DTOC(), DTOS(), ETOS(), LTOS(), MTOS(), RTOS(), SET STRICT, STR()


Description

The TOSTRING() function evaluates the expression in <expr> and returns the result as a string. The <expr> can be any valid string, date, datetime, logical or numeric expression.

Where <expr> is a date or datetime expression, the string returned will conform to the current SET DATE, SET SEPARATOR, SET SECONDS and SET CENTURY settings, in the same format as DTOC() or TTOC().

The optional <expN> is used to specify the length of the string returned. If the length is shorter than that required by <expr>, strings, dates and datetimes are truncated to the right and numerics truncated to the left.


Example

? tostring({03/29/2003})
03/29/2003
? tostring({03/29/2003},5)
03/29
 
? tostring(10 * 10)
       100
? tostring(0.45,3)
.45
 
? tostring("Hello" + " " + "World")
Hello World
? tostring("Hello" + " " + "World",5)
Hello
 
? tostring(.F.)
F


Products

Recital, Recital Server