2023/5/15

124 阅读1分钟

2023/5/15

CStringT Mid(int iFirst, int nCount) const;
CStringT Mid(int iFirst) const;

iFirst:要包含在提取的子字符串中的第一个字符的从零开始的索引 nCount:提取的字符的数量,如果未提供此参数,则提取字符串的其余部分

CString aCString = "A string";
char myString[256];
strcpy(myString, (LPCTSTR)aCString);

将CString类型转为C类型的字符串

int Replace(PCXSTR pszOld, PCXSTR pszNew);
int Replace(XCHAR chOld, XCHAR chNew);

CAtlString strBang(_T("Everybody likes epee fencing"));
int n = strBang.Replace(_T("epee"), _T("foil"));

将str中的epee替换为foil

int ReverseFind(XCHAR ch) const throw();

在CStringT对象中搜索字符的最后一个匹配项

AfxExtractSubString:从给定源字符串中提取由单个字符分隔的子字符串

CString strFull = _T("Hello,world,How,Are,You");
CString strSub;

BOOL bResult = AfxExtractSubString(strSub, strFull, 2, _T(','));

上述示例中,我们将字符串strFull分割成多个子字符串,并提取索引为2的子字符串。分隔符使用逗号(','),所以子字符串将会是"How"。如果提取成功,strSub将包含提取的子字符串,否则提取失败。

long int strtol(const char *nptr, char **endptr, int base)

nptr:strtol会扫描nptr字符串,跳过前面的空格字符,直到遇到数字或者正负符号才开始进行转换,再遇到非数字或字符串结束时('\0')结束转换
endptr:是传出参数,函数返回指向后面未被识别的第一个字符
base:转换采用的进制