The String class has a method to do just that.
String API