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
Peter Lewis kindly suggest
Discussion posts and replies are publicly visible
try this:
fn!split("1 abc def xyz 02/02/2020 aaa zzz", " ")
I can't find any documentation that supports the the behavior you describe as expected. How did you arrive at that conclusion?
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
And with this approach we have prepare the excel template from 3 input files
I half suspect that the text file might be tab-separated (just based on how it looks when pasted here), and then the Appian expression output is just trimming those tabs down to single spaces. Either way this should be easy to parse, but might require extra handling in the rule.
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)
Yes Mike Split worked for me.
I have used below code.