You need to sign in to do that
Don't have an account?

How can I split a string by a semicolon and then get the first and last name in the string?
Hi,
I have a picklist(Multiselect) field, userPkList, that contains a list users in the format of "LastName, FirstName". Each value that is select is separated by a semicolon and the very last entry does not contain a semicolon.
Example (LastName, FirstName) 1:
"Schmo, Joe; Allen, Bary; Queen, Oliver"
Example (LastName, FirstName) 2:
"Queen, Oliver, Allen, Bary; Schmo, Joe; Last1, First1; LastAbc, FirstAbc"
I need help in figuring out a way to parse this picklist (multiselect) field so that I can pull each individual Last and First name and then run a query to get the user record associated to that user. I cannot figure out a good way to do this.
Example of desired logic:
//get userPkList values into a string
//parse string so i can separate all the values based on the semicolon (;) so that i now have a list<string> that is in the format of "lastName, FirstName" per record in the list<string>
//for every string in the list<string> I am going to split the string to get first and last name
//then insert first + ' ' + last into a separate List<String>
//using the new List<String>, obtain all the users in the systems.
I have a picklist(Multiselect) field, userPkList, that contains a list users in the format of "LastName, FirstName". Each value that is select is separated by a semicolon and the very last entry does not contain a semicolon.
Example (LastName, FirstName) 1:
"Schmo, Joe; Allen, Bary; Queen, Oliver"
Example (LastName, FirstName) 2:
"Queen, Oliver, Allen, Bary; Schmo, Joe; Last1, First1; LastAbc, FirstAbc"
I need help in figuring out a way to parse this picklist (multiselect) field so that I can pull each individual Last and First name and then run a query to get the user record associated to that user. I cannot figure out a good way to do this.
Example of desired logic:
//get userPkList values into a string
//parse string so i can separate all the values based on the semicolon (;) so that i now have a list<string> that is in the format of "lastName, FirstName" per record in the list<string>
//for every string in the list<string> I am going to split the string to get first and last name
//then insert first + ' ' + last into a separate List<String>
//using the new List<String>, obtain all the users in the systems.
I have implemented a combination fo your ideas. Below is what I ended up using to get the job done.
All Answers
Try this code
If it does help, please mark like/mark this as solved.
Thanks
try this one maybe it helps you. Thanks
I have implemented a combination fo your ideas. Below is what I ended up using to get the job done.
Please try this one.
String alpha = 'A,B';
String alpha1 = 'C,D';
String alpha2 = 'E,F';
List<String> lstAlpha = new List<string>();
lstAlpha.add(alpha);
lstAlpha.add(alpha1);
lstAlpha.add(alpha2);
System.debug('------'+lstAlpha);
for(string a:lstAlpha){
List<string> b=a.split(',');
string c = string.join(b,',');
List<String> d= c.split(',');
system.debug('-------'+d[0]+'-----'+d[1]);
}