LineLength Method

Applies to TestComplete 14.93, last modified on October 12, 2021

Description

Use the LineLength method to determine the length of a given line.

Declaration

aqTextFileObj.LineLength(Line)

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

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Line

Specifies the number of the line whose length you want to know (numbering starts from zero).

Result Value

The total number of characters (including spaces and tabulations) in the specified line. The length of the trailing newline characters is ignored.

Example

The code below obtains the specified line’s length and then posts this line to the test log by letters.

JavaScript, JScript

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

   // Opens the specified file for reading
  var myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI);

  // Obtains the length of the first line
  var lLeng = myFile.LineLength(0);

  // Posts the first line by letters to the test log
  for (var i = 0; i < lLeng; i++)
    Log.Message(myFile.ReadString(1));

  // Closes the file
  myFile.Close();
}

Python

def ReadLineByLetters():
  sPath = "D:\\Files\\MyFile.txt"
  # Opens the specified file for reading 
  myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)
  # Obtains the length of the first line
  lLeng = myFile.LineLength(0)
  # Posts the first line by letters to the test log
  for i in range(0, lLeng):
    Log.Message(myFile.ReadString(i))
  # Closes the file 
  myFile.Close()

VBScript

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

   ' Opens the specified file for reading
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)

  ' Obtains the length of the first line
  lLeng = myFile.LineLength(0)

  ' Posts the first line by letters to the test log
  For i = 0 to lLeng-1
    Log.Message(myFile.ReadString(1))
  Next

  ' Closes the file
  myFile.Close()
End Sub

DelphiScript

function ReadLineByLetters;
var sPath, myFile, lLeng, i;
begin
  sPath := 'D:\Files\MyFile.txt';

   // Opens the specified file for reading
  myFile := aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI);

  // Obtains the length of the first line
  lLeng := myFile.LineLength(0);

  // Posts the first line by letters to the test log
  for i := 0 to lLeng-1 do
    Log.Message(myFile.ReadString(1));

  // Closes the file
  myFile.Close();
end;

C++Script, C#Script

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

   // Opens the specified file for reading
  var myFile = aqFile["OpenTextFile"]( sPath, aqFile["faRead"], aqFile["ctANSI"] );

  // Obtains the length of the first line
  var lLeng = myFile["LineLength"](0);

  // Posts the first line by letters to the test log
  for (var i = 0; i < lLeng; i++)
    Log["Message"]( myFile["ReadString"](1) );

  // Closes the file
  myFile["Close"]();
}

See Also

Working With Files From Scripts
LinesCount Property
Column Property

Highlight search results