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
28
29
30
int ExplodeString( const std::wstring& source, const std::wstring& exploder, StringArray& out, int limit)
{
size_t start = 0, end;
int count = 0;
std::wstring::const_iterator b0, b1 = source.begin();
while( b1 != source.end() )
{
end = source.find(exploder, start);
b0 = source.begin() + start;
if( end == std::wstring::npos || (limit>0 && ++count>limit) )
{
b1 = source.end();
}
else
{
b1 = source.begin() + end;
}
out.push_back(std::wstring(b0, b1));
start = end + exploder.length();
}
return out.size();
}