测试代码:
CDesCArray * descArray= new (ELeave) CDesCArrayFlat(2);
SplitDesL(*descArray, _L(",,ab,cde,f,,,g,hij,klmn,opq,rs,tuv,wxy,z,,,"), _L(","));
结果:
descArray = {"ab","cde","f","g","hij","klmn","opq","rs","tuv","wxy","z"};
SplitDesL(*descArray, _L(",,,,,,"), _L(","));
结果:
descArray = {}
SplitDesL(*descArray, _L("abcde"), _L(","));
结果:
descArray = {"abcde"}
/**
*
* aArray
* aDesc
* aSeparator
*/
TInt SplitDesL(CDesCArray &aArray, const TDesC &aDesc, const TDesC &aSeparator )
{
aArray.Reset();
TInt index = 0;
TPtrC fathPtr(aDesc);
index = fathPtr.Find(aSeparator);
while(index != KErrNotFound)
{
if( index > 0 )
{
/*
TBuf<100> buf;
buf = fathPtr.Mid(0, index);
RDebug::Print(_L("-----sonPtr /"%S/""), &buf);
//*/
aArray.AppendL(fathPtr.Mid(0, index));
}
fathPtr.Set( fathPtr.Mid( index + aSeparator.Length() ) );
//RDebug::Print(_L("-----fathPtr: /"%S/""), &fathPtr);
index = fathPtr.Find(aSeparator);
}
//RDebug::Print(_L("-----fathPtr: /"%S/""), &fathPtr);
if(fathPtr.Length() > 0)
aArray.AppendL( fathPtr );
return aArray.MdcaCount();
}
描述符分割的算法实现
最新推荐文章于 2024-11-02 09:55:19 发布