How can I break a string in Java?
I would like to read the line until there is room.
Then split it on another line after a space.
eg. String fullcmd = /join luke
I would like to break it into:
Cmd = /join string
String name = luke
OR
String fullcmd = /leave luke
I would like to break it into:
String cmd = /leave
String name = luke
So that I can:
if(cmd.equals"/join") System.out.println(name + " joined."); else if(cmd.equals"/leave" System.out.println(name + " left.");
I really thought about doing String cmd = fullcmd.substring(0,5);
But the length of cmd depends on the command.
java string split
Luke
source share