检查字符串的空值 [英] Checking for Null Value on String

查看:81
本文介绍了检查字符串的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何正确编码以首先检查字符串中的空值?
:sigh:

How can I code this correctly to check for null value on the string first?
:sigh:

<pre lang="vb">Dim StrValue As String = value.ToString()
            If StrValue Is Nothing Then
                StrValue = vbNullString
            End If


推荐答案

vbNullString 只是null (或Nothing).首先检查value 是否为null (Nothing).如果它是null,则不要在其上调用ToString .

这是执行此操作的一些C#代码:

vbNullString is just null (or Nothing). Check to see if value is null (Nothing) first. If it''s null, then do not call ToString on it.

Here''s some C# code that does this:

String strValue = value == null ? null : value.ToString();



这是对VB语法的自动转换(不确定它的优劣):



Here''s an automatic conversion to VB syntax (not sure how good it is):

Dim strValue As [String] = If(value Is Nothing, Nothing, value.ToString())


这篇关于检查字符串的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆