int ExplodeString const std wstring source const std wstring exploder

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int ExplodeString( const std::wstring& source, const std::wstring& exploder, StringArray& out, int limit)
{
size_t start = 0;
size_t end = 0;
int count = 0;
while( true )
{
end = source.find(exploder, start);
if( end == std::wstring::npos )
{
out.push_back(std::wstring(source.begin()+start, source.end()));
break;
}
out.push_back(std::wstring(source.begin()+start, source.begin()+end));
if( limit>0 && ++count>limit )
break;
start = end + exploder.length();
}
return out.size();
}