How To Compare a CString to the Empty String (111923)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 5.0
This article was previously published under Q111923 SUMMARY
The correct way to test a CString to see whether it is empty (or not empty)
is to use the IsEmpty() member function as shown below:
CString x = "This is a sample CString";
if (x.IsEmpty())
AfxMessageBox("The CString is EMPTY");
else
AfxMessageBox("The CString is not EMPTY");
Modification Type: | Minor | Last Reviewed: | 7/15/2004 |
---|
Keywords: | kbhowto kbString KB111923 |
---|
|