+ Start a Discussion
_Prasu__Prasu_ 

String.split('.') does not work?

One can not split string on '.' character?

 

 

Following code does not work.

String strTest = 'test.test';
String[] arrTest = strTest.split('.');

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Split takes a regular expression as its first parameter, not a string.  The period character means any character in regex land, so you need to escape it with a backslash.

 

Try:

 

 

String strTest = 'test.test';
String[] arrTest = strTest.split('\.');

 

 

 

 

All Answers

bob_buzzardbob_buzzard

Split takes a regular expression as its first parameter, not a string.  The period character means any character in regex land, so you need to escape it with a backslash.

 

Try:

 

 

String strTest = 'test.test';
String[] arrTest = strTest.split('\.');

 

 

 

 

This was selected as the best answer
Pradeep_NavatarPradeep_Navatar

Try out the sample code given below :

 

           String strTest = 'test.test1';

           String arrTest = strTest.split('\\.')[1];

 

Hope this will work.

_Prasu__Prasu_

Thanks Bob & Pradeep! It make sense. 

 

String[] arrTest = strTest.split('\\.');
Sagar ParmarSagar Parmar
String strTest = 'test.test';

String[] arrTest = strTest[0].split('\.');
Pooja Aher 13Pooja Aher 13
Hi , i have string like below 3/7/2020 8:48 PM - please - check the document one two three
3/7/2020 9:11 PM - 
looks good now
3/7/2020 9:12 PM - 
 test , i need to split it between time stamp and the text,how can i do it?