String manipulation: truncation, case conversion, masking, wrapping, and interpolation
implementation com.philiprehberger:string-kitString manipulation: truncation, case conversion, masking, wrapping, and interpolation.
implementation("com.philiprehberger:string-kit:0.2.0")
<dependency>
<groupId>com.philiprehberger</groupId>
<artifactId>string-kit</artifactId>
<version>0.2.0</version>
</dependency>
import com.philiprehberger.stringkit.*
// Truncation
"Hello World Foo Bar".truncate(15) // "Hello World..."
"Hello World Foo Bar".truncateWords(2) // "Hello World..."
// Case conversion
"hello_world".toCamelCase() // "helloWorld"
"helloWorld".toSnakeCase() // "hello_world"
"helloWorld".toKebabCase() // "hello-world"
"hello_world".toPascalCase() // "HelloWorld"
// Masking
"4111111111111111".mask(4, 12) // "4111********1111"
"user@example.com".mask(1, 4) // "u***@example.com"
"secret".mask() // "******"
// Utilities
" lots of spaces ".collapseWhitespace() // "lots of spaces"
"John Doe".initials() // "JD"
"Hello {name}!".interpolate(mapOf("name" to "Alice")) // "Hello Alice!"
| Function / Class | Description |
|---|---|
String.truncate(maxLength, ellipsis) | Smart truncation at word boundaries |
String.truncateWords(maxWords, ellipsis) | Truncate after N words |
String.toCamelCase() | Convert to camelCase |
String.toSnakeCase() | Convert to snake_case |
String.toKebabCase() | Convert to kebab-case |
String.toPascalCase() | Convert to PascalCase |
String.toTitleCase() | Convert to Title Case |
String.toConstantCase() | Convert to CONSTANT_CASE |
String.mask(start, end, char) | Mask characters in a range |
String.collapseWhitespace() | Collapse whitespace and trim |
String.initials() | Extract uppercase initials |
String.surround(wrapper) | Wrap string with prefix/suffix |
String.wordWrap(width) | Wrap at word boundaries |
String.interpolate(map) | Replace {key} placeholders |
./gradlew test # Run tests
./gradlew build # Build JAR
If you find this project useful: