With indexOf() you can find the index of the space char and then use substring() to get all chars before the space.