Forum Discussion

SL12345's avatar
SL12345
New Contributor III
3 years ago
Solved

Splitting csv file into rows and then check if specified value has 10 elements

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

  • 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.