str_data <- "1981|Kim Victoria|engineer"
# A list: one element per input string
# fixed = TRUE: "|" is a plain character
lst_data <- strsplit(str_data, "|",
fixed = TRUE)[[1]]
# One name per part
year <- as.integer(lst_data[1])
name <- lst_data[2]
position <- lst_data[3]
# A separator that is a regex: a run of spaces
words <- strsplit("red green blue", " +")[[1]]
# A plain space gives an empty string
spaced <- strsplit("red green", " ",
fixed = TRUE)[[1]]
# Without fixed = TRUE "|" is a regex
wrong <- strsplit("a|b", "|")[[1]]
# The empty string at the end is dropped
trailing <- strsplit("a,b,", ",",
fixed = TRUE)[[1]]
str(lst_data)
cat("year =", year, "\n")
cat("name =", name, "\n")
cat("position =", position, "\n")
str(words)
str(spaced)
str(wrong)
str(trailing)