mfc 怎么删除字符串的最后一个字符

2025-05-09 15:39:37
推荐回答(3个)
回答1:

CString 类中有两个成员函数:
1) .GetLength()得到字符串的长度。
2) .Left(int nCount) 从左边截取字符串,nCount是截取的字符长度。
故你要删除最后一个g;只要从左边截取该字符串的长度-1的长度。
如下:
CString str="abcdefg";
str=str.Left(str.GetLength()-1);

回答2:

CString s( _T("abcdefg") );
ASSERT( s.Mid( 0, 6 ) == _T("abcdef") );

回答3:

CString str="abcdefg";
str = str.Mid(0,str.GetLength()-1);