stringA="a; b; c; d; e; f; g; h; i; j;"s <- 4sub(sprintf("^((?:[^;]*;){%d}).*", s), "\\1", stringA)
Standard input is empty
[1] "a; b; c; d;"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!