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
r_boyd_848r_boyd_848 

String Split function fails if using a dot as criteria

 

//this will fail reporting a size of 0
string s = 'first.second';
string[] part;
part = s.split('.');
System.DEBUG(part.size());

//this will work reporting a size of 2
string s = 'first_second';
string[] part;
part = s.split('_');
System.DEBUG(part.size());

 

I'm usign API version 20. Paste this into the Execute Anonymous window of the IDE. Anyone have any ideas?

 

Best Answer chosen by Admin (Salesforce Developers) 
rscottrscott

Try this:

 

 

part = s.split('\\.');

 

 

Split actually uses regular expressions so you have to escape the "dot" (.)

All Answers

rscottrscott

Try this:

 

 

part = s.split('\\.');

 

 

Split actually uses regular expressions so you have to escape the "dot" (.)

This was selected as the best answer
r_boyd_848r_boyd_848

Ah Ahh. Thanks still recovering from C#