asp.net String.IsNullOrEmpty 方法简介
来源:不详 责任编辑:栏目编辑 发表时间:2013-07-02 00:11 点击:次
此方法在 .NET Framework 2.0 版中是新增的。
指示指定的 String 对象是 空引用(在 Visual Basic 中为 Nothing) 还是 Empty 字符串。
这个方法在VB,VB.Net, C#,C++,JScript,J#中都有,很好很强大的一个方法。
String.Empty 字段
表示空字符串。此字段为只读。
命名空间:System
程序集:mscorlib(在 mscorlib.dll 中)
语法
Visual Basic(声明)
Public Shared ReadOnly Empty As String
Visual Basic(用法)
Dim value As String
value = String.Empty
C#
public static readonly string Empty
C++
public:
static initonly String^ Empty
J#
public static final String Empty
JScript
public static final var Empty : String
备注
此字段的值为零长度字符串 ""。
示例
下面的代码示例演示如何使用 Empty 字段。
在第一个示例中,如果另一个字段的值为 空引用(在 Visual Basic 中为 Nothing),则 Empty 字符串作为默认值返回。
Visual Basic 复制代码
Dim myBinding As DataBinding = DataBindings("Text")
If Not (myBinding Is Nothing) Then
Return myBinding.Expression
End If
Return [String].Empty
End Get
C# 复制代码
DataBinding myBinding = DataBindings["Text"];
if (myBinding != null)
{
return myBinding.Expression;
}
return String.Empty;
C++ 复制代码
DataBinding^ myBinding = DataBindings[ "Text" ];
if ( myBinding != nullptr )
{
return myBinding->Expression;
}
return String::Empty;
J# 复制代码
DataBinding myBinding = get_DataBindings().get_Item("Text");
if (myBinding != null) {
return myBinding.get_Expression();
}
return("");
在第二个示例中,Compare 中使用了 Empty 字符串来测试子字符串。
Visual Basic 复制代码
Dim myString As String = "abc"
Dim test1 As Boolean = String.Compare(myString.Substring(2, 1), "c") = 0 ' This is true.
myString.Substring(3, 1) ' This throws ArgumentOutOfRangeException.
Dim test2 As Boolean = String.Compare(myString.Substring(3, 0), String.Empty) = 0 ' This is true.
C# 复制代码
String myString = "abc";
bool test1 = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true.
myString.Substring(3, 1); // This throws ArgumentOutOfRangeException.
bool test2 = String.Compare(myString.Substring(3, 0), String.Empty) == 0; // This is true.
C++ 复制代码
String^ myString = "abc";
bool test1 = String::Compare( myString->Substring( 2, 1 ), "c" ) == 0; // This is true.
myString->Substring( 3, 1 ); // This throws ArgumentOutOfRangeException.
bool test2 = String::Compare( myString->Substring( 3, 0 ), String::Empty ) == 0; // This is true.
J# 复制代码
String myString = "abc";
// This is true.
boolean test1 = String.Compare(myString.Substring(2, 1), "c") == 0;
myString.Substring(3, 1); // This throws ArgumentOutOfRangeException.
// This is true.
boolean test2 = String.Compare(myString.Substring(3, 0), " ") == 0;
JScript 复制代码
var myString : String = "abc";
var test1 : boolean = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true.
myString.
指示指定的 String 对象是 空引用(在 Visual Basic 中为 Nothing) 还是 Empty 字符串。
这个方法在VB,VB.Net, C#,C++,JScript,J#中都有,很好很强大的一个方法。
String.Empty 字段
表示空字符串。此字段为只读。
命名空间:System
程序集:mscorlib(在 mscorlib.dll 中)
语法
Visual Basic(声明)
Public Shared ReadOnly Empty As String
Visual Basic(用法)
Dim value As String
value = String.Empty
C#
public static readonly string Empty
C++
public:
static initonly String^ Empty
J#
public static final String Empty
JScript
public static final var Empty : String
备注
此字段的值为零长度字符串 ""。
示例
下面的代码示例演示如何使用 Empty 字段。
在第一个示例中,如果另一个字段的值为 空引用(在 Visual Basic 中为 Nothing),则 Empty 字符串作为默认值返回。
Visual Basic 复制代码
[复制此代码]CODE:
Dim myBinding As DataBinding = DataBindings("Text")
If Not (myBinding Is Nothing) Then
Return myBinding.Expression
End If
Return [String].Empty
End Get
C# 复制代码
[复制此代码]CODE:
DataBinding myBinding = DataBindings["Text"];
if (myBinding != null)
{
return myBinding.Expression;
}
return String.Empty;
C++ 复制代码
[复制此代码]CODE:
DataBinding^ myBinding = DataBindings[ "Text" ];
if ( myBinding != nullptr )
{
return myBinding->Expression;
}
return String::Empty;
J# 复制代码
[复制此代码]CODE:
DataBinding myBinding = get_DataBindings().get_Item("Text");
if (myBinding != null) {
return myBinding.get_Expression();
}
return("");
在第二个示例中,Compare 中使用了 Empty 字符串来测试子字符串。
Visual Basic 复制代码
[复制此代码]CODE:
Dim myString As String = "abc"
Dim test1 As Boolean = String.Compare(myString.Substring(2, 1), "c") = 0 ' This is true.
myString.Substring(3, 1) ' This throws ArgumentOutOfRangeException.
Dim test2 As Boolean = String.Compare(myString.Substring(3, 0), String.Empty) = 0 ' This is true.
C# 复制代码
[复制此代码]CODE:
String myString = "abc";
bool test1 = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true.
myString.Substring(3, 1); // This throws ArgumentOutOfRangeException.
bool test2 = String.Compare(myString.Substring(3, 0), String.Empty) == 0; // This is true.
C++ 复制代码
[复制此代码]CODE:
String^ myString = "abc";
bool test1 = String::Compare( myString->Substring( 2, 1 ), "c" ) == 0; // This is true.
myString->Substring( 3, 1 ); // This throws ArgumentOutOfRangeException.
bool test2 = String::Compare( myString->Substring( 3, 0 ), String::Empty ) == 0; // This is true.
J# 复制代码
[复制此代码]CODE:
String myString = "abc";
// This is true.
boolean test1 = String.Compare(myString.Substring(2, 1), "c") == 0;
myString.Substring(3, 1); // This throws ArgumentOutOfRangeException.
// This is true.
boolean test2 = String.Compare(myString.Substring(3, 0), " ") == 0;
JScript 复制代码
[复制此代码]CODE:
var myString : String = "abc";
var test1 : boolean = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true.
myString.
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>