Return to Snippet

Revision: 2258
at January 25, 2007 08:52 by splorp


Initial Code
function trimWhitespace(value) {
    var result = value.match(/^\s*(.*\S)\s*$/);
    if (result !== null && result.length === 2)
        return result[1];
    else
        return value;
};

Initial URL

                                

Initial Description
Trims leading and trailing spaces from a string value and returns the result as a new string.

Initial Title
Trim Leading & Trailing Whitespace

Initial Tags
format, text

Initial Language
JavaScript