mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-18 05:23:59 +00:00
120 lines
2.8 KiB
Markdown
120 lines
2.8 KiB
Markdown
strman-java
|
|
------
|
|
|
|
A Java 8 string manipulation library without any dependencies. It is inspired by [dleitee/strman](https://github.com/dleitee/strman).
|
|
|
|
|
|
## Available Functions
|
|
|
|
* [append](https://github.com/shekhargulati/strman-java#appendvalue-strings)
|
|
* [appendArray](https://github.com/shekhargulati/strman-java#appendarrayvalue-strings)
|
|
* [at](https://github.com/shekhargulati/strman-java#atvalue-index)
|
|
* [between](https://github.com/shekhargulati/strman-java#betweenvalue-start-end)
|
|
* [between](https://github.com/shekhargulati/strman-java#betweenvalue-start-end)
|
|
* [chars](https://github.com/shekhargulati/strman-java#charsvalue)
|
|
* [collapseWhitespace](https://github.com/shekhargulati/strman-java#collapsewhitespacevalue)
|
|
|
|
|
|
## append(value, strings...)
|
|
|
|
This method will append `strings` to the `value`.
|
|
|
|
```java
|
|
import static strman.Strman.append;
|
|
String title = "s";
|
|
String result = append(title, "tr","m","an");
|
|
// result = "strman"
|
|
```
|
|
|
|
|
|
## appendArray(value, strings)
|
|
|
|
This method will append all the values in `strings` array to the `value`.
|
|
|
|
```java
|
|
import static strman.Strman.appendArray;
|
|
String title = "s";
|
|
String result = appendArray(title, new String[]{"tr","m","an"});
|
|
// result = "strman"
|
|
```
|
|
|
|
## at(value, index)
|
|
|
|
Gets the character at index.
|
|
|
|
```java
|
|
import static strman.Strman.at;
|
|
String result = at("foobar", 0);
|
|
// result = "f"
|
|
```
|
|
|
|
## between(value, start, end)
|
|
|
|
Returns array with strings between `start` and `end`.
|
|
|
|
```java
|
|
import static strman.Strman.between;
|
|
String[] parts = between("[abc][def]", "[", "]";
|
|
// parts = ["abc","def"]
|
|
```
|
|
|
|
## chars(value)
|
|
|
|
Returns a String array consisting of the characters in the String.
|
|
|
|
```java
|
|
final String title = "title";
|
|
char[] result = chars(title);
|
|
// result = ["t", "i", "t", "l", "e"]
|
|
```
|
|
|
|
|
|
## collapseWhitespace(value)
|
|
|
|
Replace consecutive whitespace characters with a single space.
|
|
|
|
```java
|
|
final String input = " foo bar ";
|
|
final String result = collapseWhitespace(title);
|
|
// result = "foo bar";
|
|
```
|
|
|
|
## contains(value, needle, caseSensitive)
|
|
|
|
Verifies that the needle is contained in value.
|
|
|
|
```java
|
|
boolean result = contains("foo bar", "BAR", true);
|
|
// result = false
|
|
|
|
boolean result = contains("foo bar", "FOO");
|
|
// result = true
|
|
```
|
|
|
|
## containsAll(value, needles, caseSensitive)
|
|
|
|
Verifies that all needles are contained in value.
|
|
|
|
```java
|
|
boolean result = containsAll("foo bar", new String[]{"FOO", "bar"});
|
|
// result = true
|
|
|
|
boolean result = containsAll("foo bar", new String[]{"FOO", "bar"}, true);
|
|
// result = false
|
|
```
|
|
|
|
## containsAny(value, needles, caseSensitive)
|
|
|
|
Verifies that one or more of needles are contained in value.
|
|
|
|
```java
|
|
String title = "foo bar";
|
|
String needles = ["foo", "bar", "test"];
|
|
String result = containsAny(title, needles, true);
|
|
// result = true
|
|
```
|
|
|
|
## Other functions that can be added
|
|
|
|
1. head
|
|
2. tail |