Http://hi.baidu.com/ccskun/blog/item/9c4d033219ab5bfe1b4cff41.html/cmtid/1ce9b84445d57e2dcffca3d3
|
Int_ptr split_cstring (const cstring & source, // The original string to be truncated
Cstringarray & DEST, // split String Array
Const cstring & Division // delimiter string
) // Usage: Split (strviewstring, DEST, "<Div id =" pro_detail "> ");
{
If (source. isempty ())
Return-1;
DeST. removeall ();
Int Len = Division. getlength ();
Int Ifirst = 0;
Int ncount = 0;
Int Pos = 0;
Int pre_pos =-1;
While (-1! = POS)
{
If (-1 = pre_pos)
Pos = source. Find (Division, POS );
Else
Pos = source. Find (Division, (Pos + 1 ));
If (-1 = pre_pos)
{
Ifirst = 0;
If (-1 = POS)
Ncount = source. getlength ();
Else
Ncount = Pos;
}
Else
{
Ifirst = pre_pos + Len;
If (-1! = POS)
Ncount = pos-pre_pos-len;
Else
Ncount = source. getlength ()-pre_pos-len;
}
DeST. Add (source. mid (Ifirst, ncount ));
Pre_pos = Pos;
}
Return DeST. getcount ();
|
I wrote one,
Int pa_cstringsplit (cstring strsource, cstring strsplitter, cstringarray & sadestination ){
Int m_ilen_source = strsource. getlength ();
Int m_ilen_splitter = strsplitter. getlength ();
Int istart = 0;
Int ilen = 0;
Int IPOs = 0;
Sadestination. removeall ();
Do {
IPOs = strsource. Find (strsplitter, istart );
If (-1 = IPOS ){
Ilen = m_ilen_source-istart;
} Else {
Ilen = IPOs-istart;
}
Sadestination. Add (strsource. mid (istart, ilen ));
Istart + = ilen + m_ilen_splitter;
} While (istart <m_ilen_source );
Return true;
}