It would be useful if you made the test program and worked with it to learn how to use indexOf and substring. The posted code does not show what is in the String s or print out the value of space or bar or first or third so I can't say if anything is wrong with the code.
One problem I see is space-2? Why the value -2? What if the number has a different number of digits?
Same with space+5 What if the value is longer or shorter than expected? substring with a single value will return the String from that value to the end of the String.
Make the simple test program, compile it and execute it. If you have any questions about what it does, post the code and the full contents of the console from when you execute it. Add some comments asking your questions.