473,327 Members | 2,090 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,327 software developers and data experts.

How can I check if a string is empty?

Hello
How can I check if a string is empty?

Thanks


Nov 15 '05 #1
4 34531
I mean if the string is equal to "" or has blank characters such as tab or
space, it all cases supposed are empty
Nov 15 '05 #2
Hamed,

You can check it against the Empty constant on the string class, which
is an empty string. This is different from a null reference, which means
that you don't refer to any string at all. For the most part, they are
probably the same, but if you want to check against all cases, you can do
the following:

bool pblnEmpty = (str == null || str.Length == 0);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Hamed" <ha***@esol-co.com> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
Hello
How can I check if a string is empty?

Thanks

Nov 15 '05 #3
Hi,

you can use String.Empty to check that!!!

Regards,
Madhu

MVP | MCSD.NET
-----Original Message-----
Hello
How can I check if a string is empty?

Thanks


.

Nov 15 '05 #4
looking for empty or containing a space... this will work.
Also, if the list of characters you want to consider a "space" character is
outside the normal set, you can specify them in the String.Trim method that
I use in the second "if" statement below.

Hope this helps,
---- Nick

public bool IsMyStringEmpty(string Target)
{
if (Target.Length == 0)
return true;
else if (Target.Trim().Length == 0)
return true;
return false;
}
"Hamed" <ha***@esol-co.com> wrote in message
news:ut**************@tk2msftngp13.phx.gbl...
I mean if the string is equal to "" or has blank characters such as tab or
space, it all cases supposed are empty

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ad | last post by:
I have a string like string sNo. I want to cast it to int with int.Parse(sNo) but if the string is null or empty, it will thow exception. I must check if sNo is not null and is not empty before...
5
by: Shapper | last post by:
Hello, I am using this code line to check i a variable exists: If cookie Is Nothing Then .... How can I check if cookie is empty when cookie exists? Thanks, Miguel
6
by: John A Grandy | last post by:
how are people dealing with the situation where a function accepts a String representation of a date ... but a control on the page or form returns a Date value ... strangely, these Date values...
19
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
2
by: shapper | last post by:
Hello, I need to check if a string is empty. Should I use: String.IsNullOrEmpty(MyString) or MyString Is Nothing? What is the difference?
7
by: lphang | last post by:
I am reading a simple text file that will contains three set of string values as follow: "1234567", "ABC123456", "" I have my codes as follow trying to check for an empty string, with the input...
31
by: noagbodjivictor | last post by:
How to check if a string is empty in python? if(s == "") ??
2
by: =?Utf-8?B?TWlrZSBPS0M=?= | last post by:
VB 2005 All developers face this issue; so I'm sure Microsoft was a solution for it. What is the built in method to check DBNull in a recordset field? NOT a typed dataset. I don't want to...
15
by: puzzlecracker | last post by:
What is the quickest way to check that the following: const line; only contains whitespace, in which case to ignore it. something along these lines: isspacedLine(line); Thanks
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.