int getnum(char *str) { assert(str); char *lp = str; int result = 0; for(;;) { lp = strchr(lp, ';'); if(!lp) return result; lp = ++lp; } return result; }
int getnum(char *str) { assert(str); char *lp = str; int result = 0; for(;;) { lp = strchr(lp, ';'); if(!lp) return result; lp = ++lp; result++; } return result; }
CString str1=str; int i=str1.Replace(';',';');
不说清楚,给你源代码你直接看 int CString::Replace(TCHAR chOld, TCHAR chNew) { int nCount = 0; // short-circuit the nop case if (chOld != chNew) { // otherwise modify each character that matches in the string CopyBeforeWrite(); LPTSTR psz = m_pchData; LPTSTR pszEnd = psz + GetData()->nDataLength; while (psz < pszEnd) { // replace instances of the specified character only if (*psz == chOld) { *psz = chNew; nCount++; } psz = _tcsinc(psz); } } return nCount; }
{
assert(str);
char *lp = str;
int result = 0;
for(;;)
{
lp = strchr(lp, ';');
if(!lp) return result;
lp = ++lp;
}
return result;
}
{
assert(str);
char *lp = str;
int result = 0;
for(;;)
{
lp = strchr(lp, ';');
if(!lp) return result;
lp = ++lp;
result++;
}
return result;
}
int i=str1.Replace(';',';');
int CString::Replace(TCHAR chOld, TCHAR chNew)
{
int nCount = 0; // short-circuit the nop case
if (chOld != chNew)
{
// otherwise modify each character that matches in the string
CopyBeforeWrite();
LPTSTR psz = m_pchData;
LPTSTR pszEnd = psz + GetData()->nDataLength;
while (psz < pszEnd)
{
// replace instances of the specified character only
if (*psz == chOld)
{
*psz = chNew;
nCount++;
}
psz = _tcsinc(psz);
}
}
return nCount;
}