03-28-2023 01:51 AM
Hi snaplogic experts,
how can i split csv file into rows and then check if value after 8th semicolon has 10 values?
1;2566;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7,8,9,10;Eur;Euro;USD
2;2567;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7;Eur;Euro;USD
3;2566;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7,8,9,10;Eur;Euro;USD
lets say i have values mentioned above, i can split file into rows ($content.split(‘\n’)) but how can i check in second step if after 8th semicolon there is 10 values? (values are separated with comma)
1st row will be true, 2nd row is false (because only 7 values) and 3rd will be true as well
thank you
Solved! Go to Solution.
03-28-2023 07:37 AM
Hi @SL12345,
If you want to do this with expression then try this:
$content.split("\n").map(row => {row: row, lengthValuse:row.split(';')[8].split(',').length })
Regards,
Viktor N.
03-28-2023 07:37 AM
Hi @SL12345,
If you want to do this with expression then try this:
$content.split("\n").map(row => {row: row, lengthValuse:row.split(';')[8].split(',').length })
Regards,
Viktor N.
03-29-2023 12:51 AM
Thank you Viktor … and is there any way how to do it if i have input as a string ?
1;2566;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7,8,9,10;Eur;Euro;USD\n2;2567;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7;Eur;Euro;USD\n3;2566;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7,8,9,10;Eur;Euro;USD\n
03-29-2023 03:52 AM
Hi @SL12345,
In the sample expression that I was writing, I was working on the sample with input as a string. Below is the sample that I was using.
[
{
"content": "1;2566;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7,8,9,10;Eur;Euro;USD\n2;2567;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7;Eur;Euro;USD\n3;2566;28.3.2023;28.3.2023;10;10;15;11;1,2,3,4,5,6,7,8,9,10;Eur;Euro;USD"
}
]
For the expression to work, is expected the ‘content’ field on the input of the mapper with the CSV data inside as a string.
Regards,
Viktor N.