VB6 等效于 string.IsNullOrEmpty [英] VB6 equivalent of string.IsNullOrEmpty
问题描述
我正在处理遗留应用程序,但我的 VB6 技能不是很好.我需要检查 String 字段是否已初始化并设置为 null/nothing 或空字符串以外的其他内容.在 C# 中,我会做类似的事情:
I'm doing some work on a legacy application, and my VB6 skills aren't that great. I need to check whether a String field has been initialized and set to something other than null/nothing or an empty string. In C# I'd just do something like:
if (string.IsNullOrEmpty(myObj.Str))
我不确定 VB6 中的等价物是什么,而且我对使用 If myObj.Str = ""
并称其为好感到紧张.这样做的正确方法是什么?
I'm not sure what the equivalent to this was in VB6, and I'm nervous about using If myObj.Str = ""
and calling it good. What's the correct way to do this?
澄清一下,如果以下任何一条为真,我想要一些返回 True 的东西:
To clarify, I want something that will return True if any of the following are true:
- 该字段尚未初始化
- 该字段为空字符串(str = "", length = 0)
- 该字段设置为 null、Nothing 或 vbnull,或适用于 VB6 字符串的任何形式的 null 值.
该字段原本是一个 Long,我替换的代码检查了它是否设置为 0.
The field was originally a Long, and the code I'm replacing checked whether it was set to 0.
推荐答案
VB6 旨在简单
使用
If str = "" Then
' uninitialised, null or empty ""
- 字符串会自动初始化为 [编辑] 空字符串.
- 空字符串是 vbNullString.
- 但是不用担心空字符串.对于(几乎)任何字符串操作,VB6 空字符串都与空字符串 "" 没有区别.
- Strings are automatically initialized to [edit] a null string.
- The null string is vbNullString.
- But don't worry about null strings. A VB6 null string is indistinguishable from an empty string "" for (almost) any string manipulation.
这篇关于VB6 等效于 string.IsNullOrEmpty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!