Parsing data from .txt file

HI all,

I'm trying to parse data from a .txt file which contains data as mentioned below using readTextFromFile() function.

Text in file :" 1   abc    def    xyz   02/02/2020   aaa   zzz"

ouput of readTextFromFile() function: "1 abc def xyz 02/02/2020 aaa zzz"

Expected output: text array like {"1", "abc", "def", "xyz", "02/02/2020, "aaa", "zzz"}

Kindly suggest on framing the expression rule to remove the white spaces from the text and then placing each text at different index as mentioned above

kindly suggest

  Discussion posts and replies are publicly visible

Parents Reply
  • I'm getting data from a third party application in a .txt file from where i have to read the data and prepare an excel template.

    once i am able to get the data in form of array then leaving the data at index 1 and index 2 rest will be used form the cdt for the excel.

    i.e if input file has data as: "1 abc def xyz 02/02/2020 aaa zzz"

    then generated excel will be something like below

    def xyz 02-02-2020 aaa  zzz

    And with this approach we have prepare the excel template from 3 input files

Children
  • Did the split() function work for your use case? I'm a bit unclear what the issue is now because that should generate an array with each of the items separated. If it doesn't work with a space (" "), you might need to find whatever character is separating the items and use char(<your character number here>) as the separator in the split function.

  • Yes Peter, split() function worked form me, it was just i have used fn!char(9) to replace the blank space.

    I have used below Code Snippet to get the resolution.

    a!localVariables(
    local!fileData: readtextfromfile(
    txtFile:ri!file,
    preserveLineBreaks:true()
    ),
    local!dataArray: if(
    rule!APN_isEmpty(local!fileData),
    {},
    a!forEach(
    items: split(
    local!fileData,
    rule!APN_replaceNull(fn!char(9), ";")
    ),
    expression: trim(fv!item)
    )
    ),
    local!dataArray
    )