473,785 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.empty

cj
What is string.empty used for?

I can't say: if string.empty then
I have to use: if string = "" then

which is ok, I just want to know what .empty is for.
Apr 19 '06 #1
14 2350
CJ,

There are endless methods to tell that a string exist however does not
contain any character.

One of those is string.empy another one string="" and string=nothing
although that initializes.

In this newsgroup is once taken the string="" for the string without any
character.

However I would not botter to much. The only dangerous one can be the
string=nothing, because that test as well on a string that was in advance no
string (Is Nothing)

I hope this helps,

Cor

"cj" <cj@nospam.nosp am> schreef in bericht
news:uM******** ******@TK2MSFTN GP05.phx.gbl...
What is string.empty used for?

I can't say: if string.empty then
I have to use: if string = "" then

which is ok, I just want to know what .empty is for.

Apr 19 '06 #2
"cj" <cj@nospam.nosp am> schrieb:
What is string.empty used for?

I can't say: if string.empty then
I have to use: if string = "" then

which is ok, I just want to know what .empty is for.


\\\
If x = String.Empty Then
...
End If
///

is semantically equivalent to

\\\
If x = "" Then
...
End If
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Apr 19 '06 #3
Use String.Empty to initialise strings to zero-length.

Dim s As String
s = String.Empty

To check whether a string is zero length, check the Length property.

If s.Length = 0 Then
'...
End If

http://www.gotdotnet.com/team/fxcop/...ingLength.html
--
=============== =======
Clive Dixon
Digita Ltd. (www.digita.com)
"cj" <cj@nospam.nosp am> wrote in message
news:uM******** ******@TK2MSFTN GP05.phx.gbl...
What is string.empty used for?

I can't say: if string.empty then
I have to use: if string = "" then

which is ok, I just want to know what .empty is for.

Apr 19 '06 #4
To add on what Herfried and Cor have already said, I prefer the use of
String.Empty to "". Yes, they're syntactically correct, but the few extra
keystrokes are worth the added clarity. Is there a space in there that I
can't see becuase of the IDE's font setting? Is one of the double quotes
really two single quotes? Better to avoid the potential for confusion and
just use String.Empty.

- Mitchell S. Honnert
"cj" <cj@nospam.nosp am> wrote in message
news:uM******** ******@TK2MSFTN GP05.phx.gbl...
What is string.empty used for?

I can't say: if string.empty then
I have to use: if string = "" then

which is ok, I just want to know what .empty is for.

Apr 19 '06 #5
cj
Well, I see I typed my question a bit off again. When I posted
if string.empty

I meant it to be interpreted
if mystring.empty

which I assumed would return a True or False and it doesn't.
I didn't expect for anyone to think I meant using it like
if mystring = string.empty

But ok, I see what .empty is all about now. And I don't like it.
mystring = "" has been around for ages now an is obvious beyond any
doubt to me so I surely don't think saying mystring = string.empty is
any better. Heck I was confusing in my post. But then that's just my
opinion. :)

Thanks to everyone for explaining .empty to me!
Mitchell S. Honnert wrote:
To add on what Herfried and Cor have already said, I prefer the use of
String.Empty to "". Yes, they're syntactically correct, but the few extra
keystrokes are worth the added clarity. Is there a space in there that I
can't see becuase of the IDE's font setting? Is one of the double quotes
really two single quotes? Better to avoid the potential for confusion and
just use String.Empty.

- Mitchell S. Honnert
"cj" <cj@nospam.nosp am> wrote in message
news:uM******** ******@TK2MSFTN GP05.phx.gbl...
What is string.empty used for?

I can't say: if string.empty then
I have to use: if string = "" then

which is ok, I just want to know what .empty is for.


Apr 19 '06 #6
"cj" <cj@nospam.nosp am> schrieb:
Well, I see I typed my question a bit off again. When I posted
if string.empty

I meant it to be interpreted
if mystring.empty

which I assumed would return a True or False and it doesn't.
I didn't expect for anyone to think I meant using it like
if mystring = string.empty
That's because 'String.Empty' is shared.
But ok, I see what .empty is all about now. And I don't like it.
Dito.
mystring = "" has been around for ages now an is obvious beyond any doubt
to me so I surely don't think saying mystring = string.empty is any
better.


Full ACK. I wonder why the VB compiler doesn't emit 'String.Empty' for
empty-string literals.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 19 '06 #7
Herfried K. Wagner [MVP] wrote:
"cj" <cj@nospam.nosp am> schrieb:

.. . .
mystring = "" has been around for ages now an is obvious beyond any
doubt to me so I surely don't think saying mystring = string.empty is
any better.


Full ACK. I wonder why the VB compiler doesn't emit 'String.Empty' for
empty-string literals.

Wouldn't that be nice - from the little I understand of I.L.Code, the
compiler does come up with something a bit different in each case (not
surprisingly).

Given ...

If s1 = String.Empty Then

.... the ILCode produced looks like:

IL_0001: ldloc.0
IL_0002: ldsfld string [mscorlib]System.String:: Empty
IL_0007: ldc.i4.0
IL_0008: call int32 [Microsoft.Visua lBasic]
....CompilerSer vices.StringTyp e::StrCmp( string, string, bool )

But if you use the "old-fashioned" ...

If s1 = "" Then

.... the compiler produces this instead:

IL_0001: ldloc.0
IL_0002: ldstr ""
IL_0007: ldc.i4.0
IL_0008: call int32 [Microsoft.Visua lBasic]
....CompilerSer vices.StringTyp e::StrCmp( string, string, bool )

So does it really matter?
Is "ldstr" so much slower than "ldsfld" that "String.Emp ty" really is
worth all the extra typing?

<advocate owner="devil" >
Is String.Empty really so much more readible than ""?

Regards,
Phill W.
Apr 20 '06 #8
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> schrieb:
mystring = "" has been around for ages now an is obvious beyond any
doubt to me so I surely don't think saying mystring = string.empty is
any better.
Full ACK. I wonder why the VB compiler doesn't emit 'String.Empty' for
empty-string literals.

Wouldn't that be nice - from the little I understand of I.L.Code, the
compiler does come up with something a bit different in each case (not
surprisingly).

Given ...

If s1 = String.Empty Then

... the ILCode produced looks like:

IL_0001: ldloc.0
IL_0002: ldsfld string [mscorlib]System.String:: Empty
IL_0007: ldc.i4.0
IL_0008: call int32 [Microsoft.Visua lBasic]
...CompilerServ ices.StringType ::StrCmp( string, string, bool )

But if you use the "old-fashioned" ...

If s1 = "" Then

... the compiler produces this instead:

IL_0001: ldloc.0
IL_0002: ldstr ""
IL_0007: ldc.i4.0
IL_0008: call int32 [Microsoft.Visua lBasic]
...CompilerServ ices.StringType ::StrCmp( string, string, bool )

So does it really matter?


IMO no.
Is "ldstr" so much slower than "ldsfld" that "String.Emp ty" really is
worth all the extra typing?
IMO no.
<advocate owner="devil" >
Is String.Empty really so much more readible than ""?


IMO no.

However, it's true that the 'ldsfld' instruction is slightly faster than the
'ldstr' instruction. I don't see any reason for the VB compiler not to emit
'ldsfld' + 'String.Empty' instead of 'ldstr' for "", as both are
semantically equivalent and thus no problem could arise.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 20 '06 #9
>Is String.Empty really so much more readible than ""?
More readable enough that it's worth the few extra keystrokes, yes. I
personally don't get the near obsession some programmers have with saving a
few keystrokes. As a percentage of all overall development, the time it
takes to actually type the code is small. Besides, in most cases, you write
the code once, but it's read dozens of time. So, even if you take three
extra seconds to type a more explicit reference (be it String.Empty or
anything else), you more than make up for the "investment " of the single
write during the multiple reads.

Is this a big deal? Not really. I happen to prefer String.Empty to ""
because I believe the former to be a bit more clear and that's enough for
me. What I find interesting, though, is that this discussion seems to
paralel in a way the arguments of C# vs. VB.NET. C# people love that fact
that they save a few keystrokes with their cryptic language. I prefer to
type a bit extra and have my code more easilly understood by more people.
Sure, if you know C#, then you know what weird combination of punctuation
marks you have to create to get the functionality you need, but is this
in-built obfuscation really worth the relatively small savings in
keystrokes? I prefer VB.NET, so obviously I don't think so. To me, it's
like driving ten miles out of your way to save a penny per gallon on gas.

I'm not trying to start another C# vs. VB.NET holy flame war here. It's just
that the principle of "" vs String.Empty reminded me of some of the same
points, albeit on a much smaller scale.

- Mitchell S. Honnert

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message
news:e2******** **@yarrow.open. ac.uk...
Herfried K. Wagner [MVP] wrote:
"cj" <cj@nospam.nosp am> schrieb:

. . .
mystring = "" has been around for ages now an is obvious beyond any
doubt to me so I surely don't think saying mystring = string.empty is
any better.


Full ACK. I wonder why the VB compiler doesn't emit 'String.Empty' for
empty-string literals.

Wouldn't that be nice - from the little I understand of I.L.Code, the
compiler does come up with something a bit different in each case (not
surprisingly).

Given ...

If s1 = String.Empty Then

... the ILCode produced looks like:

IL_0001: ldloc.0
IL_0002: ldsfld string [mscorlib]System.String:: Empty
IL_0007: ldc.i4.0
IL_0008: call int32 [Microsoft.Visua lBasic]
...CompilerServ ices.StringType ::StrCmp( string, string, bool )

But if you use the "old-fashioned" ...

If s1 = "" Then

... the compiler produces this instead:

IL_0001: ldloc.0
IL_0002: ldstr ""
IL_0007: ldc.i4.0
IL_0008: call int32 [Microsoft.Visua lBasic]
...CompilerServ ices.StringType ::StrCmp( string, string, bool )

So does it really matter?
Is "ldstr" so much slower than "ldsfld" that "String.Emp ty" really is
worth all the extra typing?

<advocate owner="devil" >
Is String.Empty really so much more readible than ""?

Regards,
Phill W.

Apr 20 '06 #10

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

Similar topics

4
2305
by: Cyrus D. | last post by:
Hi guys, What's the best way to test for an empty form value ? I am doing it like this now: $test = $_POST; if(strlen($test) < 1) // it is empty ! Maybe I can just go:
13
3405
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to <foo/>) From XHTML specification:
4
4817
by: Ramiro Barbosa, Jr. | last post by:
All, In regards to the call below, I was wondering why is it that the 'szMessage' receiving buffer results in an empty one, but by printing 'ret' it indicates the number of bytes I am indeed receiving! int ret = recvfrom(receivingSocket,szMessage,sizeof(szMessage),0,sockaddr*)&addr_Cli, &clilen); Any ideas?
12
17115
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested. This is okay in some cases (such as <tbody>), but problematic for other tags (such as <option>). Some tags (td, th, ...) do not produce warnings when they are empty.
2
26715
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as empty elements in the XML. How to do that ? I don't understand why there is no simple option to specify the output format, or did I miss something ? regards andreas
11
4608
by: Dan Bass | last post by:
which one do you use and why? MyString == null || MyString == "" vs MyString == null || MyString.Length == 0
9
2374
by: Søren M. Olesen | last post by:
Hi Can someone tell me how to implement something similar to String.Empty ?? Given a class called myValue Public class myValue private id as integer private value as string end class
2
2022
by: Bob Stearns | last post by:
I thought that the given expression was always TRUE if "not_there" wasn't among the keys (or subscripts if you will) of $_SESSION. Below find a dump of $_SESSION, a small snippet of code and the results. I really don't understand. A new pair of eyes may be able to spot what should be an obvious bug. Thanks for looking. _SESSION=array 16 { userid=>bob; setname=>Junk_Cows; setuser=>jhough;
26
2795
by: anonieko | last post by:
In the past I always used "" everywhere for empty string in my code without a problem. Now, do you think I should use String.Empty instead of "" (at all times) ? Let me know your thoughts.
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.