XtremeBaumer XtremeBaumer - 1 year ago 139
Java Question

How to split string at single Backslash java

so i get this string from a method:

and i need to split it at the backslashes. i tried to replace the single backslashes with some other characters but it doesn't work. the overall task i have to accomplish is to convert the String to a
. if anyone has an idea on how to do it please share it. i didn't find any working solution in here thats why i ask again

my approach:

String datum=getComponentDateTextField().getText();
// datum is "21\11\2016"
datum=datum.replaceAll("\\\\", ".");
String[] dates=datum.split(".");
LocalDate dPresent = this.getDate();
dPresent=dPresent.of(Integer.parseInt(dates[0]), Integer.parseInt(dates[1]), Integer.parseInt(dates[2]));

Answer Source

Don't split. Just parse:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy\\MM\\dd");
LocalDate dPresent = LocalDate.parse(datum, formatter);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download