commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruno P. Kinoshita (JIRA)" <>
Subject [jira] [Commented] (LANG-1108) Function to replace multiple whitespaces by a character and trim
Date Mon, 05 Dec 2016 02:45:58 GMT


Bruno P. Kinoshita commented on LANG-1108:

Oh, today I learned :-)

I think this solves the first part, and the remainder can be solved via other existing functions

    public static void main(String[] args) {
        String value = "   This is     quite the   test.  ";
        String value2 = StringUtils.normalizeSpace(value).replace(' ', '_');

Results in

   This is     quite the   test.  

So I think this can be achieved with existing functions from [lang] and JRE. What do you think

> Function to replace multiple whitespaces by a character and trim
> ----------------------------------------------------------------
>                 Key: LANG-1108
>                 URL:
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: Marco Janc
>             Fix For: Discussion
> In form applications where user can input data its very often not wished to have successive
whitespace characters.
> A function that will replace multiple whitespace characters with a single space (or passed
string/character) would be a nice feature since I myself repeat this method in many applications.
> Something like a shortcut for:
>     value.replace("\\s+", " ").trim()

This message was sent by Atlassian JIRA

View raw message