strsplit
In this page:
strsplit
strsplit(x, split) splits a string into pieces wherever the separator pattern occurs, returning a list (since each input string could split into a different number of pieces). Accessing the first result requires indexing into the list, like strsplit(x, ",")[[1]]. This is the standard way to parse delimited text like CSV rows.
Note: strsplit() always returns a list, even for a single string input -- use [[1]] to get the character vector of pieces out.
Example: strsplit
csv_line <- "apple,banana,cherry"
parts <- strsplit(csv_line, ",")[[1]]
print(parts)
cat("Second item:", parts[2], "\n")
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: