0
String tem = '1SD,"MASK, ALEXIS",AETNA,W265925029,1119707362,7/1/2022,3/28/2022,"$4,500.00 ",Detox,"$1,126.50 ",25%';

here i wanna iterate over each an every element by splitting them using comma but at the same time omitting the comma inside the double quotes.

1 Answer 1

2

split(regExp)

Returns a list that contains each substring of the String that is terminated by either the regular expression regExp or the end of the String.

Try then something like this.

String tem = '1SD,"MASK, ALEXIS",AETNA,W265925029,1119707362,7/1/2022,3/28/2022,"$4,500.00 ",Detox,"$1,126.50 ",25%';

System.debug(tem.split('(,)(?=(?:[^"]|"[^"]*")*$)'));

for (String part : tem.split('(,)(?=(?:[^"]|"[^"]*")*$)')) {
    System.debug(part);
}

//Output
// (1SD, "MASK, ALEXIS", AETNA, W265925029, 1119707362, 7/1/2022, 3/28/2022, "$4,500.00 ", Detox, "$1,126.50 ", ...)
// 1SD
// "MASK, ALEXIS"
// AETNA
// W265925029
// 1119707362
// 7/1/2022
// 3/28/2022
// "$4,500.00 "
// Detox
// "$1,126.50 "
// 25%

Resources:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .