What's the best way of writing robust code so that a variable can be checked for null and blank.
e.g.
string a;
if((a != null) && (a.Length() > 0))
{
//do some thing with a
}
I have a DataReader and a StringBuilder (C#.NET) used in the following way;
while (reader.Read())
{
sb.AppendFormat("{0},{1},{2},",reader["Col1"], reader["Col2"], reader["Col3"]);
}
Which works great for my use, but when a row is null I need it to return "null", instead of just "". What would be a good way of accomplishing that?
Suggestions are very appreciated
response.setHeader(keys[i].toString(),value);
in a servlet is throwing null pointer exception even though none of keys[i] or value are null why is it so?
If I have 5 String variables and between 0 and 5 of them are null or empty is there an easy/short way of returning the first one that is not null or empty? I am using .NET 3.5
Hi,
I have a problem with my string that returns (null)
Here's the MainViewController:
NSString *leftWebViewUrl;
MainViewController *mainViewController;
@property (nonatomic, retain) NSString *leftWebViewUrl;
@property (nonatomic, retain) MainViewController *mainViewController;
leftWebViewUrl = [NSString stringWithString:leftWebView.request.URL.absoluteString];
leftSharingViewController.leftWebViewUrl = leftWebViewUrl;
Here's the leftSharingViewController (just the NSString declaration)
NSString *leftWebViewUrl;
@property (nonatomic, retain) NSString *leftWebViewUrl;
From some reason I get (null)
Thanks
Help me settle a dispute with a coworker:
Does setting a variable or collection to null in Java aid in garbage collection and reducing memory usage? If I have a long running program and each function may be iteratively called (potentially thousands of times): Does setting all the variables in it to null before returning a value to the parent function help reduce heap size/memory usage?
One of job interview questions on C pointer here is the following: what is null pointer assignment error?
I've googled for a while and don't see any reasonable explanation. What is that? Trying to write through a null pointer? Something architecture- or environment-specific? What exactly is that error?
From what I understand in the documentation, it returns null if it fails, but it seems to me there is an exception ready for every fail scenario.
In what standard scenario will this function actually return a null value?
The data in my dabatase comes from an external source and where ever there is no data passed, I keep NULL in those places. Can anyone tell me if there are any implications in using NULL to represent empty value?
Should I follow some other convention like 'data_not_available'? or something like that?
Can anyone suggest?
Why do this:
// If parameter cannot be cast to Point return false.
TwoDPoint p = obj as TwoDPoint;
if ((System.Object)p == null)
{
return false;
}
Instead of this:
// If parameter cannot be cast to Point return false.
TwoDPoint p = obj as TwoDPoint;
if (p == null)
{
return false;
}
I don't understand why you'd ever write ((System.Object)p)?
Regards,
Dan
I want to do something like this
$.get('/Controller/Action/', { model : null }, function(data) {});
Unfortunatelly it doesn't work. In server side the value of the model is {object}.
How do I get null?
Which approach is better to use:
BoundField.NullDisplayText isn't set. NULL-case is foreseen in SQL query, i.e. SELECT ISNULL(amount, 0) FROM table
or
BoundField.NullDisplayText is set, e.g. "0.00 %". NULL-case isn't foreseen in SQL query, i.e. SELECT amount FROM table
What do you think?
In MySQL
Select 1 from mytable
and
select null from mytable
both return the same number of rows. While select count(1) from mytable returns the rowcount and select count(null) from mytable always returns 0. Why?
What's the best way of writing robust code so that a variable can be checked for null and blank.
e.g.
string a;
if((a != null) && (a.Length() > 0))
{
//do some thing with a
}
When doing a search in active record I'm looking for record's that do not have an archived bit set to true.
Some of the archived bits are null (which are not archived) others have archived set to false.
Obviously,
Project.all(:conditions => {:archived => false})
misses the projects with the archived bits with null values. How can all non-archived projects be selected wtih active record?
The folloqing is the excpetion I am getting
The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
below is my LINQ Statement where QuestionId is the primary key in my table
var questionViewsData = from questionViews in objDc.SC_QuestionsViews
join questions in objDc.SC_Questions
on questionViews.QuestionId equals questions.QuestionId into qs
from questions in qs.DefaultIfEmpty()
where questionViews.CreatedDate.Date == new DateTime(2010, 4,27)
select new
{
Selected =(questions == null ?-1:questions.QuestionId),
QuestioinTitle = questions.Title,
VotesCount = questions.VotesCount
};
Let me know how to resolve this
My OCSP client is sending me the following HTTP request:
POST <NULL> HTTP/1.0
Content-Type: application/ocsp-request
Content-Length: 120
The NULL is not mentioned in the RFC for HTTP 1.0. Does that make this a malformed request?
i have a code like
res = doc.evalute(xpathExpr,doc,function(prefix) { return namespaces[prefix] || null;}, XPathResult.ANY_TYPE,null );
here doc is DOM document node
when i run for loop like this
for(i in doc)alert(i);
it gives evalute method
but when i tried to use this method on dom node it giving me error like
xpathResult not defined...
i'm working in android browser
thanks in advance....
I'm using the following code to hide stderr on Linux/OSX for a Python library I do not control that writes to stderr by default:
f = open("/dev/null","w")
zookeeper.set_log_stream(f)
Is there an easy cross platform alternative to /dev/null? Ideally it would not consume memory since this is a long running process.
can someone please help me with this javascript:void(null)
I found it used in link buttons as follows
<a onclick="ProcessResponse()" href="javascript:void(null)" >Accept Data</a>
Hi,
Is there any function to replace the special characters by null in informatica
if we used replacestr function, i think we should specify all special characters
as follows replacestr(input,'!','~','@','#','$','%','^','&','*',null)
But we dont know what are teh special characters will be coming as input.
can u please let me know that which function will be suitable.
I have the following structure in a Java Web Application:
TheProject
-- [Web Pages]
-- -- [WEB-INF]
-- -- -- abc.txt
-- -- index.jsp
-- [Source Packages]
-- -- [wservices]
-- -- -- WS.java
In WS.java, I am using the following code in a Web Method:
InputStream fstream = this.getClass().getResourceAsStream("abc.txt");
But it is always returning a null. I need to read from that file, and I read that if you put the files in WEB-INF, you can access them with getResourceAsStream, yet the method is always returning a null.
Any ideas of what I may be doing wrong?
I have a model called user which has_one email. I put the foreign key (NOT NULL) inside users table.
Now I'm trying to save it in the following way:
@email = Email.new(params[:email])
@email.user = User.new(params[:user])
@email.save
This raises a db exception, because the foreign key constraint is not met (NULL is inserted into email_id). How can I elegantly solve this or is my data modeling wrong?