Questions tagged [isnullorempty]

Questions regarding checking value both null and isEmpty

164 questions
199
votes
8 answers

Check if list is empty in C#

I have a generic list object. I need to check if the list is empty. How do I check if a List is empty in C#?
lakshganga
  • 2,355
  • 6
  • 21
  • 22
193
votes
8 answers

Difference between IsNullOrEmpty and IsNullOrWhiteSpace in C#

What are differences between these commands in C# string text= " "; 1-string.IsNullOrEmpty(text.Trim()) 2-string.IsNullOrWhiteSpace(text)
Asieh hojatoleslami
  • 3,240
  • 7
  • 31
  • 45
144
votes
4 answers

SQLite select where empty?

In SQLite, how can I select records where some_column is empty? Empty counts as both NULL and "".
Timo Huovinen
  • 53,325
  • 33
  • 152
  • 143
143
votes
6 answers

How can I check whether a string variable is empty or null in C#?

How can I check whether a C# variable is an empty string "" or null? I am looking for the simplest way to do this check. I have a variable that can be equal to "" or null. Is there a single function that can check if it's not "" or null?
Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427
97
votes
11 answers

How to check whether all properties of an object are null or empty?

I have an object, lets call it ObjectA, and that object has 10 properties that are all strings. var myObject = new {Property1="",Property2="",Property3="",Property4="",...} Is there anyway to check to see whether all these properties are null or…
akd
  • 6,538
  • 16
  • 70
  • 112
76
votes
12 answers

Does C# have IsNullOrEmpty for List/IEnumerable?

I know generally empty List is more prefer than NULL. But I am going to return NULL, for mainly two reasons I have to check and handle null values explicitly, avoiding bugs and attacks. It is easy to perform ?? operation afterwards to get a return…
Eric Yin
  • 8,737
  • 19
  • 77
  • 118
75
votes
8 answers

'IsNullOrWhitespace' in JavaScript?

Is there a JavaScript equivalent to .NET's String.IsNullOrWhitespace so that I can check if a textbox on the client-side has any visible text in it? I'd rather do this on the client-side first than post back the textbox value and rely only on…
Scott
  • 4,066
  • 10
  • 38
  • 54
75
votes
6 answers

One liner for If string is not null or empty else

I usually use something like this for various reasons throughout an application: if (String.IsNullOrEmpty(strFoo)) { FooTextBox.Text = "0"; } else { FooTextBox.Text = strFoo; } If I'm going to be using it a lot I will create a method that…
user2140261
  • 7,855
  • 7
  • 32
  • 45
49
votes
4 answers

Check if string variable is null or empty, or full of white spaces

How can I check if a string variable is null or empty, or full with space characters in Twig? (Shortest possible, maybe an equivalent to CSharp's String.IsNullOrWhiteSpace() method)
Guillermo Gutiérrez
  • 17,273
  • 17
  • 89
  • 116
27
votes
9 answers

R: Remove multiple empty columns of character variables

I have a data frame where all the variables are of character type. Many of the columns are completely empty, i.e. only the variable headers are there, but no values. Is there any way to subset out the empty columns?
user702432
  • 11,898
  • 21
  • 55
  • 70
24
votes
3 answers

How to use IsNullOrEmpty in VB.NET?

Why doesn't the following compile in VB.NET? Dim strTest As String If (strTest.IsNullOrEmpty) Then MessageBox.Show("NULL OR EMPTY") End if
CJ7
  • 22,579
  • 65
  • 193
  • 321
21
votes
3 answers

How to check null and empty condition using Thymeleaf in one single operation?

Is there any way to check both null and empty condition in Thymeleaf? Approach 1 1) .variable1?.variable2?.variable3 2) variable!=null 3) variable!='' If we combine two conditions like (variable!='' And variable!=null) I am having issue when…
Pradeep
  • 1,947
  • 3
  • 22
  • 45
15
votes
7 answers

Check if variable is_undefined in PHP

In PHP, I want to check if a variable has not been set/defined, where setting a variable NULL is considered set/defined. I'm aware everything here: http://php.net/manual/en/types.comparisons.php including isset(), empty(), and is_null(). None of…
tjbourke
  • 221
  • 1
  • 2
  • 8
15
votes
10 answers

C# String.IsNullOrEmpty: good or bad?

After an incident at work where I misused String.IsNullOrEmpty with a Session variable, a fellow coworker of mine now refuses to accept my usage of String.IsNullOrEmpty. After some research, apparently there's a bug listed for IsNullOrEmpty on MSDN…
osij2is
  • 1,546
  • 3
  • 12
  • 21
12
votes
9 answers

How to remove empty values from multidimensional array in PHP?

I've been looking a lot of answers, but none of them are working for me. This is the data assigned to my $quantities array: Array( [10] => Array([25.00] => 1) [9] => Array([30.00] => 3) [8] => Array([30.00] => 4) [12] =>…
Richard-MX
  • 484
  • 1
  • 6
  • 16
1
2 3
10 11