I got a project in C++ which I need to edit. This is a declaration of variable:
LPSTR hwndTitleValue = (LPSTR)GlobalAlloc(GPTR,(sizeof(CHAR) * hwndTitleSize));
How to check if this string is empty?
I tried simply with if(hwndTitleValue == "")
but it always returns false. How to check if this string is empty?
EDIT
I also need to check if the file is attached. Here is the code of the file:
// Attachment
OFSTRUCT ofstruct;
HFILE hFile = OpenFile( mmsHandle->hTemporalFileName , &ofstruct , OF_READ );
DWORD hFileSize = GetFileSize( (HANDLE) hFile , NULL );
LPSTR hFileBuffer = (LPSTR)GlobalAlloc(GPTR, sizeof(CHAR) * hFileSize );
DWORD hFileSizeReaded = 0;
ReadFile( (HANDLE) hFile , hFileBuffer, hFileSize, &hFileSizeReaded, NULL );
CloseHandle( (HANDLE) hFile );
How to check if hFile
is empty?
The Java programming language distinguishes between null and empty strings. An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters.
isEmpty() String method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false. The isEmpty() method of String class is included in java string since JDK 1.6. In other words, you can say that this method returns true if the length of the string is 0.
isBlank() vs isEmpty() The difference between both methods is that isEmpty() method returns true if, and only if, string length is 0. isBlank() method only checks for non-whitespace characters. It does not check the string length.
Using the isEmpty() Method The isEmpty() method returns true or false depending on whether or not our string contains any text. It's easily chainable with a string == null check, and can even differentiate between blank and empty strings: String string = "Hello there"; if (string == null || string. isEmpty() || string.
The easiest way to check if a string is empty is to see if the first character is a null byte:
if( hwndTitleValue != NULL && hwndTitleValue[0] == '\0' ) {
// empty
}
You can use strlen
or strcmp
as in other answers, but this saves a function call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With