Trim common portions from both sides of a vector of strings
Source:R/strtrimcommon.R
strtrimcommon.RdTrim common portions from both sides of a vector of strings
Arguments
- x
A vector of strings
- split
A
characterto use for splitting. Ifsplitis empty (i.e.split = ''),xis split into single characters. Otherwise,xis split onsplitboundaries.- USE.NAMES
logical; if
TRUEusexasnamesfor the result.- return.all
logical; if
FALSE(the default), returns only the striped strings. IfTRUE, returns a list with elementsleft,strings,right, containing left and right common portions, and the trimmed strings, respectively.
Value
A (named) vector of strings, or a list of string vectors (see
parameter return.all for details).
Examples
x <- c('/tmp/remind2_test-convGDX2MIF_fulldata.gdx',
'/tmp/remind2_test-Ariadne_fulldata.gdx',
'/tmp/remind2_test-NAVIGATE_fulldata.gdx',
'/tmp/remind2_test-NGFS_fulldata_oneRegi.gdx',
'/tmp/remind2_test-SHAPE_fulldata.gdx')
strtrimcommon(x, USE.NAMES = TRUE)
#> /tmp/remind2_test-convGDX2MIF_fulldata.gdx
#> "convGDX2MIF_fulldata"
#> /tmp/remind2_test-Ariadne_fulldata.gdx
#> "Ariadne_fulldata"
#> /tmp/remind2_test-NAVIGATE_fulldata.gdx
#> "NAVIGATE_fulldata"
#> /tmp/remind2_test-NGFS_fulldata_oneRegi.gdx
#> "NGFS_fulldata_oneRegi"
#> /tmp/remind2_test-SHAPE_fulldata.gdx
#> "SHAPE_fulldata"
x <- c('Some|name|with|common|text|elements',
'Some|name|without|extra|text|elements')
strtrimcommon(x, split = '|', return.all = TRUE)
#> $left
#> [1] "Some|name"
#>
#> $strings
#> [1] "with|common" "without|extra"
#>
#> $right
#> [1] "text|elements"
#>