[SalesForce] apex string split

Unable to split string by multiple characters.

String myString = 'abc$$$xyz';
string[] myArray = myString.Split('$$$');
System.Debug(myArray.Size());

I get result for myArray.Size = 1 and when myArray = 'abc$$$xyz'

Please shed some light

Best Answer

String.split() expects a regular expression, not a string.

Use

myString.Split('\\$\\$\\$');

(Thanks to @Mugambo)

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