how to split a string after every 4th character cpp code example
Example 1: how ot split a string every fourth eter
>>> line = '1234567890'
>>> n = 2
>>> [line[i:i+n] for i in range(0, len(line), n)]
['12', '34', '56', '78', '90']
Example 2: split string on character c++
std::stringstream test("this_is_a_test_string");
std::string segment;
std::vector<std::string> seglist;
while(std::getline(test, segment, '_'))
{
seglist.push_back(segment);
}
// seglist = {"this", "is", "a", "test", "string"};
Example 3: c++ split at character
std::stringstream test("this_is_a_test_string");
std::string segment;
std::vector<std::string> seglist;
while(std::getline(test, segment, '_'))
{
seglist.push_back(segment); //Spit string at '_' character
}
Example 4: python convert strings to chunks
s = '1234567890'
o = []
while s:
o.append(s[:2])
s = s[2:]