Storages & Files ReadText
ReadText method

Reads text from the stream (from the current position).


variable = object.ReadText(numChars)


numChars - Number of characters to read or a special constant:
positive number - the specified number of characters will be read.
negative numbers have special meaning:
-2 (cReadAll) - The entire stream (or remaining portion of it depending on the current position) is read as signle string
-1 (cReadLine) - One line of text is read. The text line is assumed to end with the line separator as it is specified by the textLineSeparator property.
-3 (cReadLineAny) - Advanced version of the previous (-1). This reads one line but applies more heuristic logic - recommended if you work with text files created by unknown operating system (e.g. the line separator can be different). See remarks.


Set sf = Server.CreateObject("newObjects.utilctls.SFMain")
Set file = sf.OpenFile("C:\MyFile.txt")
' Open exiting text file
' Read 10 characters
Response.Write file.ReadText(10)
' Read one line (non-heuristic)
Response.Write file.ReadText(-1)
' Read one line (heuristic)
Response.Write file.ReadText(-3)
' Read the remaining stream as whole
Response.Write file.ReadText(-2)


The text is assumed UNICODE or ANSI depending on the unicodeText property.

When -1 (cReadLine) constant is used the line is assumed to end with the line separator exatcly as it is specified in the textLineSeparator property. Other combinations will not be recognized. However this option does not require stream to be seekable (see Seek) and can be used on any stream object - external or built-in.

When -3 (cReadLineAny) is used the stream should be seekable and the end of line is detected more carefully. The line is assumed to end with any of the characters in the string specified by the textLineSeparator property. It is assumed that the line separator may contain more characters but there are no duplicated characters in it. The method automatically skips the rest of the delimiter using this rule and positions there. Method is proved to work correctly with all the popular text files (MAC, UNIX, Windows). The default setting for the textLineSeparator is good text files coming from MAC, UNIX, Windows.

Applies to: SFStream object

See also: textLineSeparator, codePage, unicodeText

newObjects Copyright 2001-2006 newObjects [ ]