ReadToSymbol Method

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

The ReadToSymbol method retrieves the text fragment that starts from the current position within a file and runs to the first occurrence of the specified character(s) (either printable or not).

Declaration

aqTextFileObj.ReadToSymbol(Symbol)

aqTextFileObj An expression, variable or parameter that specifies a reference to an aqTextFile object
Symbol [in]    Required    String    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Symbol

Defines one or more symbols to be used as a delimiter. This parameter is case-sensitive.

Result Value

A string containing the text from the cursor position to the given character(s). If no matching delimiters were found, the method returns an empty string.

Remarks

On success, the cursor position is shifted to the character that follows the retrieved text.

Example

The code below writes some text to the file and then reads the file content to the specified string and posts the content to the test log.

JavaScript, JScript

function ReadFileToSymbol()
{
  var sPath = "D:\\Files\\MyFile.txt";

   // Opens the specified file for reading and writing
  var myFile = aqFile.OpenTextFile(sPath, aqFile.faReadWrite, aqFile.ctANSI);
  
  myFile.Write("The file content will be posted to the test log.");
  
  // Specifies the string
  var Str = "will be";
  
  myFile.SetPosition(0, 0);
  // Reads the file to the specified string
  var FileCon = myFile.ReadToSymbol(Str);
  // Posts the file content from the beginning to the specified string
  // to the test log
  Log.Message(FileCon);
  
  // Closes the file
  myFile.Close();
}

/*
The routine produces the following output:

The file content
*/

Python

def ReadFileToSymbol():
  sPath = "D:\\Files\\MyFile.txt"
  # Opens the specified file for reading and writing 
  myFile = aqFile.OpenTextFile(sPath, aqFile.faReadWrite, aqFile.ctANSI)  
  myFile.Write("The file content will be posted to the test log.")
  # sSpecifies the string
  Str = "will be"
  myFile.SetPosition(0, 0)
  # Reads the file to the specified string
  FileCon = myFile.ReadToSymbol(Str)
  # Posts the file content from the beginning to the specified string
  # to the test log
  Log.Message(FileCon)
  # Closes the file 
  myFile.Close()

# The routine produces the following output:
# The file content

VBScript

Sub ReadFileToSymbol
  sPath = "D:\Files\MyFile.txt"

   ' Opens the specified file for reading and writing
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faReadWrite, aqFile.ctANSI)
  
  myFile.Write("The file content will be posted to the test log.")
  
  ' Specifies the string
  Str = "will be"
  
  Call myFile.SetPosition(0, 0)
  ' Reads the file to the specified string
  FileCon = myFile.ReadToSymbol(Str)
  ' Posts the file content from the beginning to the specified string
  ' to the test log
  Log.Message(FileCon)
  
  ' Closes the file
  myFile.Close()
End Sub

' The routine produces the following output:
' The file content

DelphiScript

function ReadFileToSymbol;
var sPath, myFile, Str, FileCon;
begin
  sPath := 'D:\Files\MyFile.txt';

   // Opens the specified file for reading and writing
  myFile := aqFile.OpenTextFile(sPath, aqFile.faReadWrite, aqFile.ctANSI);
  
  myFile.Write('The file content will be posted to the test log.');
  
  // Specifies the string
  Str := 'will be';
  
  myFile.SetPosition(0, 0);
  // Reads the file to the specified string
  FileCon := myFile.ReadToSymbol(Str);
  // Posts the file content from the beginning to the specified string
  // to the test log
  Log.Message(FileCon);
  
  // Closes the file
  myFile.Close();
end;

{
The routine produces the following output:

The file content
}

C++Script, C#Script

function ReadFileToSymbol()
{
  var sPath = "D:\\Files\\MyFile.txt";

   // Opens the specified file for reading and writing
  var myFile = aqFile["OpenTextFile"]( sPath, aqFile["faReadWrite"], aqFile["ctANSI"] );
  
  myFile["Write"]("The file content will be posted to the test log.");
  
  // Specifies the string
  var Str = "will be";
  
  myFile["SetPosition"](0, 0);
  // Reads the file to the specified string
  var FileCon = myFile["ReadToSymbol"](Str);
  // Posts the file content from the beginning to the specified string
  // to the test log
  Log["Message"](FileCon);
  
  // Closes the file
  myFile["Close"]();
}

/*
The routine produces the following output:

The file content
*/

See Also

Working With Files From Scripts
Write Method
WriteLine Method
ReadAll Method
ReadLine Method
ReadString Method

Highlight search results