+ 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