Forum Discussion

slecault's avatar
slecault
Contributor
14 years ago
Solved

How to loop for each line of a multi-line string

I need to split a text file into many small ones.  My source text files are in the range of 1500 to 8000 lines. The source file contains a list of controls with all their properties (this file ...
  • HKosova's avatar
    14 years ago
    Hi Stephane,



    Basically, you need to split the string by the new line character and then iterate through individual items in the resulting array. For example:

    var arr = str.split("\r\n");

    for (var i = 0; i < arr.length; i++)

    {

      // Do something with arr

    }




    You can also loop through the text using TestComplete's aqString.GetListItem object if you set aqString.ListSeparator to the new line character ("\r\n" in JScript, vbNewLine constant in VBScript or #13#10 in DelphiScript). Have a look at examples in the linked topics.





    By the way, your file looks similar to an INI file, only with a non-standard separator for name-value pairs.

    If you could modify your file into:



    ; NB: The Root section is mandatory

    [Root]



    [Control1]

    Caption='hello'

    With=12

    Height=22



    [Control333]

    Caption='hello'

    With=12

    Height=22



    you'd be able to access the sections and name-value pairs using TestComplete's Storages.INI API, instead of manually parsing the file.