My code looks like below,
string filename = '/*testfile /*testfile';
List<String> parts = filename.split('/*');
Expected output :
testfile
testfile
Output received:
t
e
s
..
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communitySplit actually expects a regular expression, so your split string is interpreted as "split when there are zero or more / characters" ("*" means "zero or more").
To avoid this behavior, you have to "escape" the "*" character with a backslash, which itself needs to be escaped with a backslash:
List<String> parts = filename.split('/\\*');
Without that escape, it tries to split every character from every other character, with the slash ("/") being stripped out entirely.
If you look at the String methods, the documentation tells you this explicitly:
split(regExp)
Returns a list that contains each substring of the String that matches this pattern.
Signature
public String[] split(String regExp)
*/
, not another/*
. Also you ignore//
style comments with this approach.