I want split the message in such a way that I can get just the information from the received line
Received : [WARNING]: \t Information \r\n
Expected : Information
public static String message(String logLine) {
String[] str = logLine.split(" ");
return str[1];
}
CodePudding user response:
The split()
method in fact accepts a regex, so you can split by whitespace in general:
logLine.split("\\s ");
CodePudding user response:
String s = "[WARNING]: \t Information \r\n"; String[] parts = s.split("\t"); String result = parts[1].trim();