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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -