chomp

Function chomp 

Source
pub fn chomp(input: &str) -> String
Expand description

Removes one newline from the end of a string if it’s there, otherwise leaves it alone. A newline is considered to be “\n”, “\r”, or “\r\n”.

§Arguments

  • input - A string slice that holds the string to be processed.

§Returns

A String with one newline removed from the end if it exists.

§Examples

use rust_string_utils::utils::chomp_chop::chomp;
let result = chomp("Hello, world!\n");
assert_eq!(result, "Hello, world!");
use rust_string_utils::utils::chomp_chop::chomp;
let result = chomp("Hello, world!\r\n");
assert_eq!(result, "Hello, world!");
use rust_string_utils::utils::chomp_chop::chomp;
let result = chomp("Hello, world!");
assert_eq!(result, "Hello, world!");