# NOT RUN {
s <- "Lorem ipsum dolor sit amet, consectetur adipisicing elit."
stri_sub(s, from=1:3*6, to=21)
stri_sub(s, from=c(1,7,13), length=5)
stri_sub(s, from=1, length=1:3)
stri_sub(s, -17, -7)
stri_sub(s, -5, length=4)
(stri_sub(s, 1, 5) <- "stringi")
(stri_sub(s, -6, length=5) <- ".")
(stri_sub(s, 1, 1:3) <- 1:2)
x <- c("12 3456 789", "abc", "", NA, "667")
stri_sub(x, stri_locate_first_regex(x, "[0-9]+")) # see stri_extract_first
stri_sub(x, stri_locate_last_regex(x, "[0-9]+")) # see stri_extract_last
stri_sub_replace(x, stri_locate_first_regex(x, "[0-9]+"),
omit_na=TRUE, replacement="***") # see stri_replace_first
stri_sub_replace(x, stri_locate_last_regex(x, "[0-9]+"),
omit_na=TRUE, replacement="***") # see stri_replace_last
stri_sub(x, stri_locate_first_regex(x, "[0-9]+"), omit_na=TRUE) <- "***"
print(x)
# }
# NOT RUN {
x %>% stri_sub_replace(1, 5, replacement="new_substring")
# }
Run the code above in your browser using DataLab