null

PHP - Checking if array index exist or is null

那年仲夏 提交于 2019-12-18 03:10:24
问题 Is there a way to check if an array index exists or is null ? isset() doesn't tell you whether the index doesn't exist or exists but is null. If I do : isset($array[$index]) || is_null($array[$index]) it won't work because if the index doesn't exist is_null will crash. How can I check this please? Also is there a way to check only if something exist, no matter if it is set to null or not? 回答1: The function array_key_exists() can do that, and property_exists() for objects, plus what Vineet1982

HashMap with Null Key and Null Value

有些话、适合烂在心里 提交于 2019-12-18 03:08:29
问题 Consider the following Code : import java.util.*; class Employee { String name; public Employee(String nm) { this.name=nm; } } public class HashMapKeyNullValue { Employee e1; public void display(){ Employee e2=null; Map map=new HashMap(); map.put(e2, "25"); System.out.println("Getting the Value When e2 is set as KEY"); System.out.println("e2 : "+map.get(e2)); System.out.println("e1 : "+map.get(e1)); System.out.println("null : "+map.get(null)); map.put(e1, ""); System.out.println("Getting the

[NSNull isEqualToString:]

半世苍凉 提交于 2019-12-18 02:58:06
问题 Im trying to set a string to "No Display name if [object objectForKey@"display_name"] is NULL". It crashing with this in the log 2011-06-16 10:58:36.251 BV API[15586:ef03] displayNameType is: NSNull 2011-06-16 10:58:36.251 BV API[15586:ef03] +[NSNull isEqualToString:]: unrecognized selector sent to class 0x1228c40 2011-06-16 10:58:36.253 BV API[15586:ef03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSNull isEqualToString:]: unrecognized selector

[NSNull isEqualToString:]

百般思念 提交于 2019-12-18 02:58:05
问题 Im trying to set a string to "No Display name if [object objectForKey@"display_name"] is NULL". It crashing with this in the log 2011-06-16 10:58:36.251 BV API[15586:ef03] displayNameType is: NSNull 2011-06-16 10:58:36.251 BV API[15586:ef03] +[NSNull isEqualToString:]: unrecognized selector sent to class 0x1228c40 2011-06-16 10:58:36.253 BV API[15586:ef03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSNull isEqualToString:]: unrecognized selector

链表的归并排序

ⅰ亾dé卋堺 提交于 2019-12-18 00:31:35
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *getmid(ListNode *head) {   ListNode *p=head;   ListNode *q=p->next;   while(q!=NULL&&q->next!=NULL)//q每次走两个,p走一个,开始时p在第一个节点,q在第二个节点   {   p=p->next;   q=q->next->next;   } return p; } ListNode * mergeList(ListNode *&l1,ListNode *&l2)//合并两个有序的链表 {   if(l1==NULL)     return l2;   if(l2==NULL)     return l1;   ListNode *head=new ListNode(0);//新建一个头结点,用于存储归并后的链表   ListNode *p=head;   while(l1!=NULL && l2!=NULL)   {   if(l1-

Why doesn't the compiler at least warn on this == null

牧云@^-^@ 提交于 2019-12-17 23:27:09
问题 Why does the C# compiler not even complain with a warning on this code? : if (this == null) { // ... } Obviously the condition will never be satisfied.. 回答1: Because you could override operator == to return true for that case. public class Foo { public void Test() { Console.WriteLine(this == null); } public static bool operator ==(Foo a, Foo b) { return true; } public static bool operator !=(Foo a, Foo b) { return true; } } Running new Foo().Test() will print "True" to the console. The other

Getting rid of null/empty string values in a C# array

风格不统一 提交于 2019-12-17 22:56:41
问题 I have a program where an array gets its data using string.Split(char[] delimiter). (using ';' as delimiter.) Some of the values, though, are null. I.e. the string has parts where there is no data so it does something like this: 1 ;2 ; ; 3; This leads to my array having null values. How do I get rid of them? 回答1: Try this: yourString.Split(new string[] {";"}, StringSplitOptions.RemoveEmptyEntries); 回答2: You could use the Where linq extension method to only return the non-null or empty values.

how to add nil to nsmutablearray?

元气小坏坏 提交于 2019-12-17 22:34:53
问题 NSArray *array = [[NSArray alloc] initWithObjects:@"ΕΛΤΑ", @"ΕΛΤΑ COURIER", @"ACS", @"ACS ΕΞΩΤΕΡΙΚΟ", @"DHL", @"INTERATTICA", @"SPEEDEX", @"UPS", @"ΓΕΝΙΚΗ ΤΑΧΥΔΡΟΜΙΚΗ", @"ΜΕΤΑΦΟΡΙΚΕΣ ΕΞΩΤΕΡΙΚΟΥ", nil]; This is working because it has nil at the end. But I add objects like this: addObject:name etc... So at the end I have to add nil I do this addObhect:nil but when I run the app it still crashes at cellForRowAtIndexPath: how can I do this work? Ok, I dont have to add nil What is the reason that

Checking for an empty field with MySQL

放肆的年华 提交于 2019-12-17 22:29:54
问题 I've wrote a query to check for users with certain criteria, one being they have an email address. Our site will allow a user to have or not have an email address. $aUsers=$this->readToArray(' SELECT `userID` FROM `users` WHERE `userID` IN(SELECT `userID` FROM `users_indvSettings` WHERE `indvSettingID`=5 AND `optionID`='.$time.') AND `email`!="" '); Is this the best way to check for an empty field in SQL? I've just tried "IS NOT NULL" and this still returned a users record without them having

Shortest way to check for null and assign another value if not

爱⌒轻易说出口 提交于 2019-12-17 22:12:09
问题 I am pulling varchar values out of a DB and want to set the string I am assigning them to as "" if they are null . I'm currently doing it like this: if (string.IsNullOrEmpty(planRec.approved_by) == true) this.approved_by = ""; else this.approved_by = planRec.approved_by.toString(); There seems like there should be a way to do this in a single line something like: this.approved_by = "" || planRec.approved_by.toString(); However I can't find an optimal way to do this. Is there a better way or