trimwhitespace
trimwhitespace is a common string processing utility that returns a new string with leading and trailing whitespace removed from the input. It preserves internal spacing and character order, altering only the elements at the boundaries. This operation is frequently used to normalize user input, configuration values, and parsing results.
Whitespace is a broad category that includes spaces, tabs, newlines, and other formatting gaps. Implementations vary
Commonly, trimwhitespace is provided as a function named trim, strip, or trimStart/trimEnd in different languages. In
Unicode handling can affect results. If a library adheres to Unicode whitespace, characters such as NBSP or
Performance is typically linear in the string length. Trimming is idempotent for strings that are already trimmed,