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.
|
I can hardly believe it but
Tried with |
|||
|
|
|
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:
The documentation provides an interesting example, if you need to use "\" as the separator:
|
||||
|
|