#white-space #truncate #string

truncate_string_at_whitespace

Truncate a &str at the closest whitespace to a specified length with unicode safety

4 stable releases

1.0.3 Apr 2, 2024
1.0.2 May 7, 2021

#375 in Text processing

Download history 1/week @ 2024-02-13 9/week @ 2024-02-20 7/week @ 2024-02-27 1/week @ 2024-03-05 1/week @ 2024-03-26 196/week @ 2024-04-02

197 downloads per month
Used in site-gen

Apache-2.0

5KB
80 lines

truncate white space

Truncate a string at a certain length, using the closest whitespace character.

Usage

Add the following to your Cargo.toml

truncate_string_at_whitespace = "1.0.2"

Then

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

No runtime deps