Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can hardly believe it but split() doesn't work on the . character:

String createDate = '01.2.2013';
String[] cd = createDate.split('.');
System.assertEquals(3, cd.size());   // Boom!

Tried with '\.' but it also doesn't work.

share|improve this question
up vote 46 down vote accepted

The separator string used in the split method is a regular expression and "." is a special character in regular expressions.

The regular expression for a literal "." is "\."

However "\" is also used to escape characters when expressing Strings in Apex, and so this character too needs escaping:

String[] cd = createDate.split('\\.');

The documentation provides an interesting example, if you need to use "\" as the separator:

List<String> parts = filename.split('\\\\');
share|improve this answer
Well that's logical...for a given value of "logical". Ta! – Marc Mar 1 '13 at 3:47
This answer now blogged: – Stephen Willcock Aug 30 '13 at 9:16
Is there any method like c# Getfilename() in apex? – user22442 Jul 26 '15 at 12:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.