Rediger

Del via


FileSystem.InputString(Int32, Int32) Method

Definition

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.

public:
 static System::String ^ InputString(int FileNumber, int CharCount);
public static string InputString (int FileNumber, int CharCount);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static string InputString (int FileNumber, int CharCount);
static member InputString : int * int -> string
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("macos")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member InputString : int * int -> string
Public Function InputString (FileNumber As Integer, CharCount As Integer) As String

Parameters

FileNumber
Int32

Required. Any valid file number.

CharCount
Int32

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

Returns

A string 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.

Attributes

Exceptions

FileNumber does not exist.

CharCount < 0 or > 214.

Examples

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)

Remarks

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.

Note

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.

Applies to

See also