-
Notifications
You must be signed in to change notification settings - Fork 0
Strings
derari edited this page Feb 21, 2013
·
3 revisions
converting to and from strings
Download: central
Maven:
<dependency>
<groupId>org.cthul</groupId>
<artifactId>cthul-strings</artifactId>
<version>1.0</version>
</dependency>
Alpha Index (Excel Columns)
AlphaIndex.toAlpha(27); // returns "AB"
AlphaIndex.fromAlpha("AB"); // returns 27
Romans.ToRoman(2992); // returns "MMCMXCII"
Romans.ToRoman2(2992); // returns "MMXMII"
Romans.FromRoman("MMXMII"); // returns 2992
JavaNames.camelCase("Hello, world!"); // returns "HelloWorld"
JavaNames.UNDER_SCORE("HTTPHeader"); // returns "HTTP_HEADER"
Like java.util.Formatter
, but allows to configure custom formats. Custom formats are accessible via conversion %i
, followed by a character, or %j
, followed by the conversion name. %I
and %J
will convert the output to uppercase.
Some additional formats are registered by default, alignment options are supported if possible.
Strings.format("%iR-%5JRomans", 3, 7); // returns "iii- VII"
Strings.format("%_|3IA %jAlpha;", 3, 4); // returns "_D_ e"
Strings.format("Found %if=1[one file][%<d files]", 2); // returns "Found 2 files"
Map<Object,Object> args = new HashMap<>();
args.put("name", "Peter");
Strings.format("Hello, %?name$if[%<<s][world]!", new SimpleArgs(args)); // returns "Hello, Peter!"
Find more example for the conditional format here.