.Net(VB、C#)で文字列の空チェック
by mogice · 2015-01-29
String.IsNullOrEmptyメソッドを利用する方法。
VB.NET
1 2 3 4 5 | Dim str As String = "ABCDE" If String.IsNullOrEmpty(str) Then Console.WriteLine("文字列は空です") End If |
C#
C#
1 2 3 4 5 6 | string str = "ABCDE"; if (string.IsNullOrEmpty(str)) { Console.WriteLine("文字列は空です"); } |
別の方法。
VB.NET
1 2 3 4 5 | Dim str As String = "ABCDE" If str Is Nothing OrElse str.Length = 0 Then Console.WriteLine("文字列は空です") End If |
C#
C#
1 2 3 4 5 6 | string str = "ABCDE"; if (str == null || str.Length == 0) { Console.WriteLine("文字列は空です"); } |