Difference between revisions of "STRTOFILE()"

From Lianjapedia
Jump to: navigation, search
Line 11: Line 11:
 
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" WIDTH="100%"
!Parameter||Description
+
!width="15%"|Parameter||Description
 
|-
 
|-
 
|<expC1>||String expression to be written to the file
 
|<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.
+
|valign="top"|<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.
+
|valign="top"|<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.
 
|<expN>||Optional settings, see below.
Line 26: Line 26:
 
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" width="100%"
!Value||Setting
+
!width="15%"|Value||Setting
 
|-
 
|-
 
|0||The string will overwrite the file's previous contents.
 
|0||The string will overwrite the file's previous contents.
Line 33: Line 33:
 
|1||The string will be appended to 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.
+
|valign="top"|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.
+
|valign="top"|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.
 
|-
 
|-
 
|}
 
|}
Line 64: Line 64:
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
[[Category:String Data]]
 
 
[[Category:String Data Functions]]
 
[[Category:String Data Functions]]
 
[Category:ASCII File Access Functions]]
 
[Category:ASCII File Access Functions]]

Revision as of 06:56, 4 February 2013

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)

[Category:ASCII File Access Functions]]