473,388 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

how to check whether a string is null or not

hi to all


can any one tell how to check whether a string is null or not;


regards
Apr 16 '07 #1
2 10521
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. String s;
  4.  
  5. if(s != null){
  6.  here you go;
  7. }
  8.  
I think this should work.

BSCode266
Apr 16 '07 #2
itsraghz
127 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. String s;
  4.  
  5. if(s != null){
  6. here you go;
  7. }
  8.  
I think this should work.

BSCode266
You can even think of this if your requirement insists you to do so.
Expand|Select|Wrap|Line Numbers
  1. if(s!=null && s.length()>0) {
  2. //do whatever you want
  3. }
  4.  
if you want to eliminate the blankspaces on both the ends of the strigns as well, use
Expand|Select|Wrap|Line Numbers
  1. if(s!=null && s.trim().length()>0){
  2. System.out.println("Valid and non-empty string!");
  3. }
  4.  
Apr 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: Nuno Paquete | last post by:
Hi group. I'm using this code to see if is there any parameter for variable "menu": if($_GET == "downloads") .... But this code log errors if there is no parameter passed (this heappens at...
26
by: JGH | last post by:
How can I check if a key is defined in an associative array? var users = new array(); users = "Joe Blow"; users = "John Doe"; users = "Jane Doe"; function isUser (userID) { if (?????)
3
by: Caspy | last post by:
I just get stuck on how to check if a user is a member of network (domain). I am building an internal tracking system with ASP.Net with Form authentication. When an user is added into the system,...
4
by: Laphan | last post by:
Hi all In my functions I'm using a double-check all the time to trap if a value has nothing in it and my question is do I need this double-check. My check line is: IF IsNull(xxx) OR...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
8
by: Earl | last post by:
What's the best way to check for null on an ExecuteScalar? The following would fire the command twice: if (cmd.ExecuteScalar() != null) { intContactID = Convert.ToInt32(cmd.ExecuteScalar()); }
11
by: -Lost | last post by:
I have this generic function (JavaScript newbie here, so don't think I am going to impress you): function blah() { var container = ''; for(var i = 0; i < arguments.length; i++) { container...
30
by: Jess | last post by:
Hello, I tried a program as follows: include<iostream> using namespace std; class A{ public:
4
by: RP | last post by:
I have a member variable of a class of type "int", and while assigning value to it in a constructor, I want to check whether it is a null. I am using following code: if (NewMember.BPLNo == null)...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.