Export (0) Print
Expand All

FileSystem.InputString Method

Returns String value that contains characters from a file opened in Input or Binary mode. The My feature gives you better productivity and performance in file I/O operations than InputString. For more information, see FileSystem.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static string InputString(
	int FileNumber,
	int CharCount
)

Parameters

FileNumber
Type: System.Int32

Required. Any valid file number.

CharCount
Type: System.Int32

Required. Any valid numeric expression specifying the number of characters to read.

Return Value

Type: System.String
Returns String value that contains characters from a file opened in Input or Binary mode. The My feature gives you better productivity and performance in file I/O operations than InputString.

ExceptionCondition
IOException

FileNumber does not exist.

ArgumentException

CharCount < 0 or > 214.

The InputString function is provided for backward compatibility and may affect performance. For non-legacy applications, the My.Computer.FileSystem object provides better performance. For more information, see File Access with Visual Basic.

Data read with the InputString function is usually written to a file by using Print or FilePut. Use this function only with files opened in Input or Binary mode.

Unlike the Input function, the InputString function returns all the characters it reads. This includes commas, carriage returns, line feeds, quotation marks, and leading spaces.

With files opened for Binary access, an attempt to read through the file by using the InputString function until EOF returns True generates an error. Use the LOF and Loc functions instead of EOF when you read binary files by using InputString, or use FileGet when you use the EOF function.

NoteNote

When reading from files, do not make security decisions about the contents of the file based on the file name extension. For example, a file named Form1.vb may not be a Visual Basic source file.

This example uses the InputString function to read one character at a time from a file and print it to the Output window. This example assumes that MyFile is a text file that has several lines of sample data.

Dim oneChar As String 
' Open file.
FileOpen(1, "MYFILE.TXT", OpenMode.Input)
' Loop until end of file. 
While Not EOF(1)
    ' Get one character.
    oneChar = (InputString(1, 1))
    ' Print to the output window.
    System.Console.Out.WriteLine(oneChar)
End While
FileClose(1)

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft