XE6如何检查UnicodeString是否为null? [英] XE6 How do you check if a UnicodeString is null?
问题描述
我正在使用C++ Builder XE6
.我得到一个UnicodeString
作为参数,我希望检查字符串是否设置为NULL,而不是空字符串.
I'm using C++ Builder XE6
. I'm getting a UnicodeString
as a parameter and I wish to check if the string is set to NULL, and not an empty string.
我尝试进行一些简单的比较,以查看参数是否为null,但似乎失败了.我正在使用==
运算符,该运算符似乎不起作用,这使我认为它已超载.
I've tried to do some simple compares to see if the param is null, but seem to be failing. I'm using the ==
operator which doesn't seem to be working, which makes me think it is overloaded.
我尝试过:
if (searchString == NULL)
在调试器视图中,它在局部变量中显示{ NULL }
的值.如果将变量添加到监视列表,则表明它具有"Data"的属性,该属性为NULL
.
In the debugger view, it shows the value of { NULL }
in the local variables. If I add the variable to the watch list, then it shows it has a property of "Data" which is NULL
.
关于如何正确进行比较的任何想法?
Any ideas on how I can properly do the compare?
推荐答案
没有像UnicodeString
的NULL
值这样的东西.字符串是一系列字符,但是NULL
是指针(好吧-实际上,它是一个计算为int 0
的宏,但是如果编译器未将其用于指示空指针,支持nullptr
).
There is no such thing as a NULL
value for a UnicodeString
. A string is a series of characters, but NULL
is a pointer (well - actually it is a macro that evaluates to an int, 0
, but it is supposed to be used to indicate null pointers if your compiler doesn't support nullptr
).
在内部,UnicodeString
的data
成员在字符串为空时为NULL,而在字符串具有至少1个字符时为非NULL.
Internally, the data
member of UnicodeString
is NULL when the string is empty, and non-NULL when the string has at least 1 character.
要检查字符串是否为空,请使用IsEmpty()
方法,该方法检查data
成员是否为NULL.只有一个空状态.像某些语言一样,空"和空"之间没有区别.
To check if the string is empty, use the IsEmpty()
method, which checks if the data
member is NULL or not. There is only one empty state; there is no distinction between "empty" and "null" like some languages have.
在调试器中看到的值是UnicodeString
的内部data
成员,而不是UnicodeString
界面的一部分.当您在调试器中看到NULL时,应将其视为空字符串.
The value you see in the debugger is the internal data
member of UnicodeString
, it is not a part of UnicodeString
's interface. When you see NULL in the debugger, you should treat it as being an empty string.
这篇关于XE6如何检查UnicodeString是否为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!