Update README.md

This commit is contained in:
Fabio Lima 2023-08-30 03:34:08 -03:00 committed by GitHub
parent 8f98e2ee36
commit d7e0bc6024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -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: