luni, 7 septembrie 2015

[OmniFaces utilities 2.0] Replace all matches of the given pattern on the given string with the given replacement


[OmniFaces utilities] The replaceAll() function replaces all matches of the given pattern on the given string with the given replacement.

Function:
Usage:

Let's suppose that we have the following string:

<c:set var="text" value="This is a String to use as an example to present raplaceAll"/>

Replacing single characters

·         replace all occurrences of 'a' with '@'

#{of:replaceAll(text, "a", "@")}
Result: This is @ String to use @s @n ex@mple to present r@pl@ceAll

·         replace all occurrences of 'e' with '3'

#{of:replaceAll(text, "e", "3")}
Result: This is a String to us3 as an 3xampl3 to pr3s3nt raplac3All

·         replace all occurrences of 't' with 'T'

#{of:replaceAll(text, "t", "T")}
Result: This is a STring To use as an example To presenT raplaceAll

·         remove all occurrences of 'o'

#{of:replaceAll(text, "o", "")}
Result: This is a String t use as an example t present raplaceAll

·         replace all occurrences of 't' with 'That'

#{of:replaceAll(text, "t", "That")}
Result: This is a SThatring Thato use as an example Thato presenThat raplaceAll

Replacing char sequences character

·         replace all occurrences of 'This' with 'That'

#{of:replaceAll(text, "This", "That")}
Result: That is a String to use as an example to present raplaceAll

·         replace all occurrences of 'String' with 'big String'

#{of:replaceAll(text, "String", "big String")}
Result: This is a big String to use as an example to present raplaceAll

·         remove all occurrences of 'is'

#{of:replaceAll(text, "is", "")}
Result: Th a String to use as an example to present raplaceAll

·         remove all occurrences of 'replaceAll'

#{of:replaceAll(text, "raplaceAll", "")}
Result: This is a String to use as an example to present

Using regular expressions

·         replace uppercase letters with '-'

#{of:replaceAll(text, "[A-Z]+", "-")}
Result: -his is a -tring to use as an example to present raplace-ll

Niciun comentariu:

Trimiteți un comentariu