str_squish_line_breaks: Trim strings with repeated line breaks

View source: R/strings.R

str_squish_line_breaksR Documentation

Trim strings with repeated line breaks

Description

[Experimental] Removes line breaks (\n and \r) from the start and end of a string and repeated line breaks inside a string.

This is an analogue of stringr::str_squish(), which trims white space from the start and end of a string and removes repeated whitespace inside a string. However stringr::str_squish() will replace line breaks inside a string with a space, which is not always desired.

Note that if there is a repeat of two different line break characters, i.e. a newline (\n) and line return (\r), the first occurrence will be kept.

See: https://github.com/tidyverse/stringr/issues/477

Usage

str_squish_line_breaks(string)

Arguments

string

String to squish

Value

String with repeeated line returns and whitespaces removed

Examples

stringr::str_squish("hello\nworld")
stringr::str_squish("hello\n\nworld")
str_squish_line_breaks("hello\nworld")
str_squish_line_breaks("hello\n\nworld")

IntegralEnvision/integral documentation built on Nov. 4, 2024, 2 p.m.