Split a string in different parts according to a delimiter character is a quite common task. Given an input string, the easiest way to get all characters until the next delimiter and put them in an output string is to use the getline function. The getline function extracts characters from an input stream and stores them into an output string until the next delimitation character is found. Moreover the getline function returns it returns the stream that’s passed to it once the characters has been extracted. Since that stream is convertible to a indicating if no error has occured, including whether or not the stream is at his end, the getline function can be used in a while loop that stops when the end of the stream has been reached. The following function split the input string in several chunks according to the specified delimiter:
Regex solution in case of multiple delimiters.
Comments