User Story
As a Salesforce developer, I want to write an Apex code snippet that can split a given full name into separate first name and last name variables, so that I can use this information for various business logic and data processing tasks in my Salesforce org.
Code
String fullName = 'Engin Basturk';
String[] nameParts = fullName.split(' ');
String firstName = nameParts[0];
String lastName = nameParts[1];
EXPLANATION
In this code, we first define the fullName
variable with the full name string. Then, we use the split()
method to split the full name into an array of strings, using the space character (' ') as the delimiter. This splits the first name and last name into two separate strings, which we then assign to the firstName
and lastName
variables, respectively.
After running this code, the firstName
variable will contain the string 'Engin', and the lastName
variable will contain the string 'Basturk'.
Video
Video does not exists.