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
chaithaly gowdachaithaly gowda 

how to convert string into a list

Hi

I have a string which is in format ('abc','xyz','efg').
Can someone please suggest how this string can be converted into list<string> with the value abc,xyz,efg.
Any help would be appreciated.

Thanks
Chaithaly
RituSharmaRituSharma
Try below logic:

str = str.replace('(','').replace(')',''); //Taking out ( and )
str = str.replace('\'',''); //Taking out '
List<String> strList = str.split(',');
 
mary smith 18mary smith 18
def Convert(string):
    li = list(string.split(" "))
    return li
  
# Driver code    
str1 = "Sales Force"
print(Convert(str1))
Output:
['Sales', 'Force']
Njmcdirect (http://www.paynjmcdirect.com)
AbhishekAbhishek (Salesforce Developers) 
Use the split method. this method will split the string using the provided regex.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm

EX:-

String str = '123, 456, 789';
List<String> lstString = str.split(',');
System.debug('-----lstString----'+lstString);

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.