R Under development (unstable) (2023-11-08 r85496 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## > ## s t r i n g s . R tests > ## > > strcat <- pracma::strcat > strcmp <- pracma::strcmp > strcmpi <- pracma::strcmpi > > strcmp(" empty", " empty") # T [1] TRUE > !strcmp("empty ", "empty") # F [1] TRUE > !strcmp("foobar", "barfoo") # F [1] TRUE > !strcmp("string", "String") # F [1] TRUE > !strcmp(c("yes", "no"), c("yes", "on")) # F [1] TRUE > !strcmp(c("abc", "abc"), c("abc")) # F [1] TRUE > strcmp(c("yes", "no"), c("yes", "no")) # T [1] TRUE > > strcmpi("string", "String") # T [1] TRUE > strcmpi(c("yes", "no"), c("Yes", "No")) # T [1] TRUE > > blanks <- pracma::blanks > deblank <- pracma::deblank > strTrim <- pracma::strTrim > strjust <- pracma::strjust > strRep <- pracma::strRep > > identical(c(blanks(0), blanks(1), blanks(2)), c("", " ", " ")) [1] TRUE > 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")) [1] TRUE > identical(strTrim(s), c("abc", "abc", "abc", "a b c", "abc", "a b c")) [1] TRUE > identical(strjust(s, justify = "center"), + c(" abc ", " abc ", " abc ", "a b c", " abc ", "a b c")) [1] TRUE > 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!")) [1] TRUE > > proc.time() user system elapsed 0.18 0.03 0.15