Questions tagged [is-empty]

Questions about items that can be described as empty or having no data value

776 questions
3929
votes
54 answers

How do I check for an empty/undefined/null string in JavaScript?

Is there a string.Empty in JavaScript, or is it just a case of checking for ""?
casademora
  • 67,775
  • 17
  • 69
  • 78
470
votes
11 answers

What is the best way to test for an empty string in Go?

Which method is best (most idomatic) for testing non-empty strings (in Go)? if len(mystring) > 0 { } Or: if mystring != "" { } Or something else?
Richard
  • 10,122
  • 10
  • 42
  • 61
337
votes
10 answers

How to find whether or not a variable is empty in Bash

How can I check if a variable is empty in Bash?
Tree
  • 9,532
  • 24
  • 64
  • 83
319
votes
12 answers

How to check if a file is empty in Bash?

I have a file called diff.txt. I Want to check whether it is empty. I wrote a bash script something like below, but I couldn't get it work. if [ -s diff.txt ] then touch empty.txt rm full.txt else touch full.txt rm…
Mich
  • 3,253
  • 2
  • 14
  • 6
263
votes
18 answers

Detect if an input has text in it using CSS -- on a page I am visiting and do not control?

Is there a way to detect whether or not an input has text in it via CSS? I've tried using the :empty pseudo-class, and I've tried using [value=""], neither of which worked. I can't seem to find a single solution to this. I imagine this must be…
JacobTheDev
  • 17,318
  • 25
  • 95
  • 158
164
votes
2 answers

ValueError when checking if variable is None or numpy.array

I'd like to check if variable is None or numpy.array. I've implemented check_a function to do this. def check_a(a): if not a: print "please initialize a" a = None check_a(a) a = np.array([1,2]) check_a(a) But, this code raises…
Light Yagmi
  • 5,085
  • 12
  • 43
  • 64
163
votes
24 answers

Check string for nil & empty

Is there a way to check strings for nil and "" in Swift? In Rails, I can use blank() to check. I currently have this, but it seems overkill: if stringA? != nil { if !stringA!.isEmpty { ...blah blah } }
netwire
  • 7,108
  • 12
  • 52
  • 86
122
votes
5 answers

Check if array is empty or null

I would like to know how to check if an array is empty or null in jQuery. I tried array.length === 0 but it didn't work. It did not throw any error either. This is the code: var album_text = new…
input
  • 7,503
  • 25
  • 93
  • 150
95
votes
13 answers

Checking if a collection is empty in Java: which is the best method?

I have two ways of checking if a List is empty or not if (CollectionUtils.isNotEmpty(listName)) and if (listName != null && listName.size() != 0) My arch tells me that the former is better than latter. But I think the latter is better. Can…
Vikrant
  • 1,809
  • 1
  • 13
  • 18
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
74
votes
7 answers

How to convert empty spaces into null values, using SQL Server?

I have a table and the columns on this table contains empty spaces for some records. Now I need to move the data to another table and replace the empty spaces with a NULL value. I tried to use: REPLACE(ltrim(rtrim(col1)),' ',NULL) but it doesn't…
niceApp
  • 2,913
  • 8
  • 35
  • 36
64
votes
8 answers

How to fully dump / print variable to console in the Dart language?

Hey there I am searching for a function which is printing a dynamic variable as completely as possible to the console in Dart language. In PHP for instance I would use var_dump() in order to get all information about a variable. In JavaScript I…
Blackbam
  • 17,496
  • 26
  • 97
  • 150
62
votes
4 answers

Why use null function instead of == [] to check for empty list in Haskell?

I am reading through the "Starting Out" chapter of Learn You a Haskell for Great Good!. It says: null checks if a list is empty. If it is, it returns True, otherwise it returns False. Use this function instead of xs == [] (if you have a list called…
徐保钰
  • 793
  • 1
  • 7
  • 17
58
votes
6 answers

Is it possible to set an object to null?

Further in my code, I check to see check if an object is null/empty. Is there a way to set an object to null?
John
  • 629
  • 1
  • 5
  • 7
55
votes
4 answers

VBA Check if variable is empty

I have an object and within it I want to check if some properties are set to False, like: If (Not objresult.EOF) Then 'Some code End if But sometimes, objresult.EOF is Empty; how can I check for this? IsEmpty function is for excel cells…
fessguid
  • 559
  • 1
  • 5
  • 3
1
2 3
51 52