https://github.com/toddself/truncate_string_at_whitespace
https://github.com/toddself/truncate_string_at_whitespace
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/toddself/truncate_string_at_whitespace
- Owner: toddself
- Created: 2021-05-07T00:22:45.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-07T01:36:36.000Z (about 5 years ago)
- Last Synced: 2025-03-15T05:12:06.403Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# truncate white space
Truncate a string at a certain length, using the closest whitespace character.
## Usage
Add the following to your `Cargo.toml`
```toml
truncate_string_at_whitespace = "1.0.2"
```
Then
```rust
use truncate_string_at_whitespace::truncate_text;
fn main () {
let s = "This is a string that I want to truncate";
let st = truncate_text(s, 12);
assert_eq!(st, "This is a");
let st2 = truncate_text(s, 16);
assert_eq!(st2, "This is a string");
}
```
## Licence
© 2021 Todd Kennedy, Apache-2.0