As part of daily life of coding I have faced issue with Java String split function.
Problem : java String Split() function should not work with delimiter as a special characters as we expected, if you write the code similar to the code for normal characters.
Solution : Use the escape characters before the special character.
e.g. String tempString = "SBS | Bhargav | Swamy";
// Gives unexpected results
// Gives unexpected results
String[] stringArray = tempString.split('' | ");
// Gives Proper results by providing two back slashes before the special character.
String[] stringArray = tempString.split('' \\ | ");
No comments:
Post a Comment