is-empty

Javascript: Checking if an object has no properties or if a map/associative-array is empty [duplicate]

耗尽温柔 提交于 2019-11-29 02:14:28
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How do I test for an empty Javascript object from JSON? Is there an easy way to check if an object has no properties, in Javascript? Or in other words, an easy way to check if a map/associative array is empty? For example, let's say you had the following: var nothingHere = {}; var somethingHere = {foo: "bar"}; Is there an easy way to tell which one is "empty"? The only thing I can think of is something like this

Best way to verify string is empty or null

对着背影说爱祢 提交于 2019-11-29 01:50:13
问题 i am sure this must have been asked before in different ways - as isEmptyOrNull is so common yet people implement it differently. but i have below curious query in terms of best available approach which is good for memory and performance both. 1) Below does not account for all spaces like in case of empty XML tag return inputString==null || inputString.length()==0; 2) Below one takes care but trim can eat some performance + memory return inputString==null || inputString.trim().length()==0; 3)

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

£可爱£侵袭症+ 提交于 2019-11-28 22:23:06
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 work. It will convert all of the values of col1 to NULL . I just want to convert only those values that have empty spaces to NULL . Did you try this? UPDATE table SET col1 = NULL WHERE col1 = '' As the commenters point out, you don't have to do ltrim() or rtrim() , and NULL columns will not match '' . I solved a similar problem using NULLIF function:

Why is String.IsNullOrEmpty faster than String.Length?

风格不统一 提交于 2019-11-28 21:21:41
ILSpy shows that String.IsNullOrEmpty is implemented in terms of String.Length . But then why is String.IsNullOrEmpty(s) faster than s.Length == 0 ? For example, it's 5% faster in this benchmark: var stopwatches = Enumerable.Range(0, 4).Select(_ => new Stopwatch()).ToArray(); var strings = "A,B,,C,DE,F,,G,H,,,,I,J,,K,L,MN,OP,Q,R,STU,V,W,X,Y,Z,".Split(','); var testers = new Func<string, bool>[] { s => s == String.Empty, s => s.Length == 0, s => String.IsNullOrEmpty(s), s => s == "" }; int count = 0; for (int i = 0; i < 10000; ++i) { stopwatches[i % 4].Start(); for (int j = 0; j < 1000; ++j)

How do I detect empty cells in a cell array?

心不动则不痛 提交于 2019-11-28 18:36:55
How do I detect empty cells in a cell array? I know the command to remove the empty cell is a(1) = [] , but I can't seem to get MATLAB to automatically detect which cells are empty. Background: I preallocated a cell array using a=cell(1,53) . Then I used if exist(filename(i)) and textscan to check for a file, and read it in. As a result, when the filename(i) does not exist, an empty cell results and we move onto the next file. When I'm finished reading in all the files, I would like to delete the empty cells of a . I tried if a(i)==[] Use CELLFUN %# find empty cells emptyCells = cellfun(

ValueError when checking if variable is None or numpy.array

梦想与她 提交于 2019-11-28 18:04:50
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 ValueError. What is the straight forward way? ValueError Traceback (most recent call last) <ipython-input-41-0201c81c185e> in <module>() 6 check_a(a) 7 a = np.array([1,2]) ----> 8 check_a(a) <ipython-input-41-0201c81c185e> in check_a(a) 1 def check_a(a): ----> 2 if not a: 3 print "please initialize a" 4 5 a = None ValueError: The truth value of an array with more than

Check if array is empty or null

只谈情不闲聊 提交于 2019-11-28 15:26:58
问题 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 Array(); $("input[name='album_text[]']").each(function(){ if( $(this).val() && $(this).val() != '') { album_text.push($(this).val()); } }); if (album_text.length === 0) { $('#error_message').html("Error"); } else { // send data } 回答1: As long as your selector is actually working, I see nothing wrong

execute Ant task if TWO conditions are met

旧时模样 提交于 2019-11-28 07:12:53
问题 The above ant script implements if dir_is_empty then git-clone else git-fetch using Ant-1.7.1 core statements: <target name="update" depends="git.clone, git.fetch" /> <target name="check.dir"> <fileset dir="${dir}" id="fileset"/> <pathconvert refid="fileset" property="dir.contains-files" setonempty="false"/> </target> <target name="git.clone" depends="check.dir" unless="dir.contains-files"> <exec executable="git"> <arg value="clone"/> <arg value="${repo}"/> <arg value="${dir}"/> </exec> <

R: Remove multiple empty columns of character variables

社会主义新天地 提交于 2019-11-28 06:58:23
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? If your empty columns are really empty character columns, something like the following should work. It will need to be modified if your "empty" character columns include, say, spaces. Sample data: mydf <- data.frame( A = c("a", "b"), B = c("y", ""), C = c("", ""), D = c("", ""), E = c("", "z") ) mydf # A B C D E # 1 a y # 2 b z Identifying and removing the "empty" columns. mydf[

Check if an Edit Text that only accepts number is not empty and the number is equal or less than 100

早过忘川 提交于 2019-11-28 06:24:41
问题 I'm building an application for receiving grades and I want to make sure that the Edit Texts are not empty and the values are less or equal to 100 I wrote this line but it crashes the application if(Integer.parseInt(editText.gettext().toString()) > 100 || editText.getText().toString().trim().length() == 0) { //Error message for example } and this is the logCat 09-04 18:21:06.331 8649-8649/com.example.nima.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.nima