I would like to split emails by an a comma and put each email into an array. The problem I'm having is that I can't put each email into each index in the string array.
public string additionalEmails {get;set;}
String[] emailTestString = new string[]{};
emailTestString = additionalEmails.split(',');
I believe the above splits the emails but then stores then all at index 0 (But i could be wrong)
I tried running a for each loop as follows:
string[] strList = new string[]{};
Integer i = 0;
for( String str : emailTestString)
{
strList[i] = str;
i++;
}
But it doesn't even enter the for each loop.
So if anyone can help me but each email into an array I would be very grateful.
Input:
Output when I display on screen:
As you can see it doesn't split by the comma.
system.debug()
to output a list (andString.split()
does return aList<String>
), Salesforce does put commas between each value. Since that's so similar to the format that you're using for input, it'd be easy to think that your code wasn't working. Printing the size of the list in a debug statement might help you confirm whether or not your code is working.