[Solved] How to get a string before character java [closed]


When you know what String you are looking for, you can try the following.

String s="description: John Newman Logged on: 03.26.2018 9:26:29";
String log1 = null;

if(s.toLowercase().contains("logged on")){
    log1 = "Logged on"; // Your desired string
}else if(s.toLowercase().contains("logged off")){
    log1 = "Logged off"; // Your desired string
}

or Simply

String log1 = (s.toLowercase().contains("logged on")) ? "Logged on":(s.toLowercase().contains("logged off")) ? "Logged off" : null;

Use boundaries if you think that logged on can be a part(substring) of User’s name as well.

3

solved How to get a string before character java [closed]