Project

General

Profile

« Previous | Next » 

Revision b5046c38

Added by Patrick Plitzner about 5 years ago

ref #8041 Add CdmUtils method to trim a string of non-word characters

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/CdmUtils.java
467 467
        return false;
468 468
    }
469 469

  
470
    /**
471
     * Removes all non-word character (i.e. *, @, %, line breaks, etc.)
472
     * from the given string
473
     * @param string the string which should be trimmed
474
     * @return the trimmed string
475
     */
476
    static public String trimNonWordCharacters(String string){
477
        return replaceNonWordCharacters(string, "");
478
    }
479

  
480
    /**
481
     * Replaces all non-word character (i.e. *, @, %, line breaks, etc.)
482
     * with the given replacement string
483
     * @param string the string which should be trimmed
484
     * @param replacement the replacement for the non-word characters
485
     * @return the trimmed string
486
     */
487
    static public String replaceNonWordCharacters(String string, String replacement){
488
        return string.replaceAll("\\W", replacement);
489
    }
490

  
470 491
    /**
471 492
     * Returns <code>false</code> if string is null, "" or string.trim() is ""
472 493
     * @see isNotEmpty(String string)

Also available in: Unified diff