Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting a string by whitespace in c++ [duplicate]

Tags:

People also ask

How do you split a string in white space?

You can split a String by whitespaces or tabs in Java by using the split() method of java. lang. String class. This method accepts a regular expression and you can pass a regex matching with whitespace to split the String where words are separated by spaces.

How split a string by space in C#?

To split a string we need delimiters - delimiters are characters which will be used to split the string. Suppose, we've the following string and we want to extract the individual words. char str[] = "strtok needs to be called several times to split a string"; The words are separated by space.

How do I split a string into multiple spaces?

To split a string by multiple spaces, call the split() method, passing it a regular expression, e.g. str. trim(). split(/\s+/) . The regular expression will split the string on one or more spaces and return an array containing the substrings.


Possible Duplicates:
C++: How to split a string?
Splitting a string

What is the best way to go about splitting a string up by whitespace in c++?

I'd like to be able to split it based on tab, space, etc. and of course ignore multiple tabs/spaces/etc. in a row as well as not have issues with having those things at the end.

Ultimately, I am going to end up storing this in a vector, but I can easily convert between data types if there is some easy built-in standard library way of splitting.

I am building this on a UNIX machine with g++, not using Microsoft Visual C++