From d7e0bc6024dafe7cbbcb089a376a8051e13262c2 Mon Sep 17 00:00:00 2001 From: Fabio Lima Date: Wed, 30 Aug 2023 03:34:08 -0300 Subject: [PATCH] Update README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 88fdb10..e645b61 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,28 @@ Instant instant = ulid.getInstant(); // 2007-02-16T02:13:14.633Z Instant instant = Ulid.getInstant("0123456789ABCDEFGHJKMNPQRS"); // 2007-02-16T02:13:14.633Z ``` +Get only the time component substring: + +```java +String ulidTimePart = ulid.toString() + .substring(0, Ulid.TIME_CHARS); // 0123456789 +``` + +Get only the random component substring: + +```java +String ulidRandPart = ulid.toString() + .substring(Ulid.TIME_CHARS, Ulid.RANDOM_CHARS); // ABCDEFGHJKMNPQRS +``` + +Insert a string between the time and random components efficiently (avoiding concatenation) ([#29](https://github.com/f4b6a3/ulid-creator/pull/29)): + +```java +String ulidExpanded = new StringBuilder(ulid.toString()) + .insert(Ulid.TIME_CHARS, "-INSERTED-") + .toString(); // 0123456789-INSERTED-ABCDEFGHJKMNPQRS +``` + --- A key generator that makes substitution easy if necessary: