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
_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?
md faheemmd faheem
Above Marked answer is wrong

This is perfect answer 

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

Please marked as correct answer