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
Nilesh ManeNilesh Mane 

How to split a string???

I want to split a string by capital letters.

 

For example : 

If

MainString = JanuaryFebruaryMarch;

then

string1 = January

string2 = February

string3 = March

 

Please help.

 

Regards,

Nil.

Best Answer chosen by Admin (Salesforce Developers) 
KapilCKapilC

Hi Nilesh

 

This code will help you.

 

String s ='JanuaryFebruaryMarch';
List<String> lstx = s.replaceAll('([A-Z])','\n$1' ).split('\n');
lstx .remove(0);
system.debug('lstx :'+lstx );
for(String a:lstx){
system.debug('Term By Term:'+a);
}
system.debug('lstx Size:'+lstx .size());
[If you got answer from my post please mark it as solution.]
Thanks,
Kapil