string - How do I Remove text before a space in java? -
string str = "hello world"; int spacepos = str.indexof(" "); if (spacepos > 0) { string youstring = str.substring(0, spacepos - 1); system.out.println(youstring); }
i want "world" result. how result?
use substring(startindex)
form of substring
method. find index of space (' '), pass result + 1 substring
method , output string starting position end. follows:
string str = "hello world"; string youstring = str.substring(str.indexof(' ') + 1); system.out.println(youstring);
Comments
Post a Comment