stringA="a; b; c; d; e; f; g; h; i; j;"
s <- "4"
stringB
<- sub
(sprintf("^((?:[^;]*;){%s}).*", s
), "\\1", stringA
)stringB
## "a; b; c; d;"
c3RyaW5nQT0iYTsgYjsgYzsgZDsgZTsgZjsgZzsgaDsgaTsgajsiCnMgPC0gIjQiCnN0cmluZ0IgPC0gc3ViKHNwcmludGYoIl4oKD86W147XSo7KXslc30pLioiLCBzKSwgIlxcMSIsIHN0cmluZ0EpCnN0cmluZ0IKIyMgICJhOyBiOyBjOyBkOyI=