-
Notifications
You must be signed in to change notification settings - Fork 0
String.tr()
nobeans edited this page Sep 13, 2010
·
8 revisions
since v0.1
This feature contributed to Groovy! Now it’s available with Groovy 1.7.3 or later. If you want to use it with Groovy 1.7.2 or previous, you can still use it with kobo-commons.
As category:
import org.jggug.kobo.commons.lang.StringCategory
use(StringCategory) {
assert "abcdefghijklmn".tr("abc", "ABC") == "ABCdefghijklmn"
assert "abcdefghijklmn".tr("a-c", "A-N") == "ABCdefghijklmn"
}
As enhanced String:
import org.jggug.kobo.commons.lang.StringUtils
StringUtils.extendMetaClass()
assert "abcdefghijklmn".tr("abc", "ABC") == "ABCdefghijklmn"
assert "abcdefghijklmn".tr("a-c", "A-N") == "ABCdefghijklmn"
As utility:
import org.jggug.kobo.commons.lang.StringUtils
assert StringUtils.tr("abcdefghijklmn", "a-n", "A-C") == "ABCCCCCCCCCCCC"
assert StringUtils.tr("abcdefghijklmn", "a-c", "A-N") == "ABCdefghijklmn"