Difference between revisions of "STRTOFILE()"

From Lianjapedia
Jump to: navigation, search
m (1 revision)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Function to write a text string out to a file
 
Function to write a text string out to a file
 
  
 
==Syntax==
 
==Syntax==
 
STRTOFILE(<expC1>, <expC2> [, <expL> | <expN2>])
 
STRTOFILE(<expC1>, <expC2> [, <expL> | <expN2>])
 
  
 
==See Also==
 
==See Also==
[[AT()]], [[ATNEXT()]], [[FCLOSE()]], [[FCREATE()]], [[FERROR()]], [[FILETOSTR()]], [[FOPEN()]], [[FREADSTR()]], [[FWRITE()]], [[MEMOREAD()]], [[MEMOWRITE()]], [[SET STRESCAPE]], [[STREXTRACT()]], [[STUFF()]], [[STR()]], [[STRTRAN()]], [[STRZERO()]], [[SUBSTR()]], [[TEXTEDIT()]], [[TRIM()]]
+
[[AT()]], [[ATNEXT()]], [[FCLOSE()]], [[FCREATE()]], [[FERROR()]], [[FILETOSTR()]], [[FOPEN()]], [[FREADSTR()]], [[FWRITE()]], [[MEMOREAD()]], [[MEMOWRITE()]], [[SET STRESCAPE]], [[STREXTRACT()]], [[STUFF()]], [[STR()]], [[STRTRAN()]], [[STRZERO()]], [[SUBSTR()]], [[TRIM()]]
 
+
  
 
==Description==
 
==Description==
 
The STRTOFILE() function writes the specified string out to the specified file and returns the number of bytes written as a numeric.
 
The STRTOFILE() function writes the specified string out to the specified file and returns the number of bytes written as a numeric.
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 27: Line 23:
 
|-
 
|-
 
|}
 
|}
 
  
 
The optional <expN> setting can be any of the following and used instead of <expL>:
 
The optional <expN> setting can be any of the following and used instead of <expL>:
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 44: Line 38:
 
|-
 
|-
 
|}
 
|}
 
 
  
 
==Example==
 
==Example==
Line 70: Line 62:
 
</code>
 
</code>
  
 
==Products==
 
Recital, Recital Server
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:String Data]]
 
[[Category:String Data]]
 
[[Category:String Data Functions]]
 
[[Category:String Data Functions]]

Revision as of 06:40, 10 February 2012

Purpose

Function to write a text string out to a file

Syntax

STRTOFILE(<expC1>, <expC2> [, <expL> | <expN2>])

See Also

AT(), ATNEXT(), FCLOSE(), FCREATE(), FERROR(), FILETOSTR(), FOPEN(), FREADSTR(), FWRITE(), MEMOREAD(), MEMOWRITE(), SET STRESCAPE, STREXTRACT(), STUFF(), STR(), STRTRAN(), STRZERO(), SUBSTR(), TRIM()

Description

The STRTOFILE() function writes the specified string out to the specified file and returns the number of bytes written as a numeric.

Parameter Description
<expC1> String expression to be written to the file
<expC2> Name of the output file. This should include the path if not in the current directory. If it does not exist, it will be created.
<expL> If True (.T.), the string will be appended to the file's previous contents. If False (.F.), the string will overwrite the file's previous contents. The default is False.
<expN> Optional settings, see below.

The optional <expN> setting can be any of the following and used instead of <expL>:

Value Setting
0 The string will overwrite the file's previous contents.
1 The string will be appended to the file's previous contents.
2 The Unicode BOM "FF FE" will be written to the start of the file. The string will overwrite the file's previous contents.
4 The UTF-8 BOM "EF BB BF" will be written to the start of the file. The string will overwrite the file's previous contents.

Example

myString = "Hello World"
 
// Create file if it does not exist, overwrite if it does
nBytes = strtofile(mystring, "myfile.txt")
 
// Append to file's previous contents
nBytes = strtofile(mystring, "myfile.txt",.T.)
 
// Create file if it does not exist, overwrite if it does
nBytes = strtofile(mystring, "myfile.txt",0)
 
// Append to file's previous contents
nBytes = strtofile(mystring, "myfile.txt",1)
 
// Create file if it does not exist, overwrite if it does.  Include Unicode BOM
nBytes = strtofile(mystring, "myfile.txt",2)
 
// Create file if it does not exist, overwrite if it does.  Include UTF-8 BOM
nBytes = strtofile(mystring, "myfile.txt",4)