function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phuc Nguyen 18Phuc Nguyen 18 

Add Double quotes to string

Hello,
I have an Apex class where I am parsing the selected values from a multiselect.
How can I add double quotes to each element?
I have big, small, medium.
I need "big","small","medium"

Any suggestion would be appreciated.
Cheers,
P
Best Answer chosen by Phuc Nguyen 18
Ravi Dutt SharmaRavi Dutt Sharma
Hi Phuc,

Please try below code, let me know if you face any issues. Thanks.
 
String multiSelectValues = 'big, small, medium';
String modifiedValues = '"' + String.join(multiSelectValues.split(', '), '","') + '"';

 

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
Hi Phuc,

Please try below code, let me know if you face any issues. Thanks.
 
String multiSelectValues = 'big, small, medium';
String modifiedValues = '"' + String.join(multiSelectValues.split(', '), '","') + '"';

 
This was selected as the best answer
sachinarorasfsachinarorasf
Hi Phuc,

Please use the below code to get the required string.

String d  =  'big, small, medium';

String[] size  = d.split(',');
String First      =     '"'+size[0]+'",'; 
String Second     =    '"'+size[1]+'",';
String Third      =    '"'+size[2]+'"';

String newString = First+Second+Third;
System.debug(newString);

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com
Phuc Nguyen 18Phuc Nguyen 18
Thanks to you both for your quick replies.
Cheers,
P