mynamedaike / string

Make String Processing Easier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

String

This package is complementary to stringr package. It includes three functions: string_insert, string_cut and string_replace. string_insert inserts a string to another string at a given position. string_cut cuts a substring between two given positions from a string. string_replace replaces a substring between two given positions in a string with another string.

Installation

devtools::install_github("mynamedaike/string")

Quick demo

Import string library

library(string)

string_insert inserts a string to another string at a given position

a <- "apple pear "
b <- "banana "
string_insert(a, b, as.integer(0))
#> [1] "banana apple pear "
string_insert(a, b, as.integer(6))
#> [1] "apple banana pear "
string_insert(a, b, as.integer(11))
#> [1] "apple pear banana "

string_cut cuts a substring between two given positions from a string

a <- "apple banana pear "
string_cut(a, as.integer(1), as.integer(6))
#> [1] "banana pear "
string_cut(a, as.integer(7), as.integer(13))
#> [1] "apple pear "
string_cut(a, as.integer(14), as.integer(18))
#> [1] "apple banana "

string_replace replaces a substring between two given positions in a string with another string

a <- "apple banana pear "
b <- "orange"
string_replace(a, b, as.integer(1), as.integer(5))
#> [1] "orange banana pear "
string_replace(a, b, as.integer(7), as.integer(12))
#> [1] "apple orange pear "
string_replace(a, b, as.integer(14), as.integer(17))
#> [1] "apple banana orange "

About

Make String Processing Easier

License:Other


Languages

Language:R 100.0%