Split string by semicolon and remove empty items and return array of string

Hello there,

I have a string input which will contain email ids. There could be possibility of values like asb@xyz.com ;fdf@xyz.com;;sdsf@xyz.com

I want to get only email ids into an array. I was trying with split and then using foreach to check if empty value or not and then add to final array. Any quicker way possible?

hi, @pieter.w

Use this single Assign activity:
yourString.Split({";"c}, StringSplitOptions.RemoveEmptyEntries)

This splits by semicolon and auto-removes empty entries from ;;
Result: String() array with only valid emails like {"asb@xyz.com", "fdf@xyz.com", "sdsf@xyz.com"}

No loops needed - ready for For Each or email activities!

1 Like

@pieter.w

This should give you the expected output in a string array

strInput.Trim.Split({";"}, StringSplitOptions.RemoveEmptyEntries).Select(Function(s) s.Trim()).ToArray()
1 Like

Hi @pieter.w ,

Try this

emailArray = inputString.Split(";"c).
Where(Function(x) Not String.IsNullOrWhiteSpace(x)).
Select(Function(x) x.Trim).
ToArray()

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.