Trimming strings

Edit on Github instead

Getting rid of leading and trailing white space in a string is called "trimming." Trimming strings is often helpful when you work with input from a user of your program.

Called on: the string to be trimmed

Arguments: None

Returns: the string without beginning or trailing white space


String trueSentence = " I have extra spaces! ";
falseSentence = trueSentence.trim();             // "I have extra spaces!";

Suggest changes

Related links

URL Topic Source