https://github.com/cran/pracma
Raw File
Tip revision: 3f1c6b45c918375fc2b65bb2a7d6e3590979cb61 authored by HwB on 12 December 2011, 00:00:00 UTC
version 0.9.1
Tip revision: 3f1c6b4
strings.R
##
##  s t r i n g s . R  tests
##

strcat <- pracma::strcat
strcmp <- pracma::strcmp
strcmpi <- pracma::strcmpi

strcmp(" empty", " empty")               # T
!strcmp("empty ", "empty")               # F
!strcmp("foobar", "barfoo")              # F
!strcmp("string", "String")              # F
!strcmp(c("yes", "no"), c("yes", "on"))  # F
!strcmp(c("abc", "abc"), c("abc"))       # F
strcmp(c("yes", "no"), c("yes", "no"))   # T

strcmpi("string", "String")              # T
strcmpi(c("yes", "no"), c("Yes", "No"))  # T

blanks <- pracma::blanks
deblank <- pracma::deblank
strtrim <- pracma::strtrim
strjust <- pracma::strjust
strrep <- pracma::strrep

identical(c(blanks(0), blanks(1), blanks(2)), c("", " ", "  "))
s <- c("  abc", "abc   ", " abc ", " a b c ", "abc", "a b c")
identical(deblank(s), c("  abc", "abc", " abc", " a b c", "abc", "a b c"))
identical(strtrim(s), c("abc", "abc", "abc", "a b c", "abc", "a b c"))
identical(strjust(s, justify = "center"),
          c(" abc ", " abc ", " abc ", "a b c", " abc ", "a b c"))
s <- c('This is a good example.', "He has a good character.",
       'This is good, good food.', "How goodgood this is!")
identical(strrep(s, 'good', 'great'),
          c('This is a great example.', "He has a great character.",
            'This is great, great food.', "How greatgreat this is!"))
back to top