473,670 Members | 2,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Empty string

M D
You know how you assume you know until you find out you don't know.

Well, I typed into a function definition "..., new String("")).

I know what I want. Everyone reading this knows what I want. However,
the 1.0 compiler has no idea what I want.

Can anyone share with me the syntax that will actually communicate the
concept to the compiler, please?

thx
md

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
21 5750
Actually I'm not sure what you want to accomplish. Creating a new
string with "new String()" automatically creates a zero length string.
So why use quotation marks?

Best Regards
Johann Blake

Nov 17 '05 #2
M D wrote:
You know how you assume you know until you find out you don't know.

Well, I typed into a function definition "..., new String("")).

I know what I want. Everyone reading this knows what I want.
However, the 1.0 compiler has no idea what I want.

Can anyone share with me the syntax that will actually communicate the
concept to the compiler, please?

thx
md

*** Sent via Developersdex http://www.developersdex.com ***


Why not use just "" ?
It's a bit of overkill to create a new string-object that you supply with
a string-literal (which is also a string-object) that has exactly the same
value as you want to end up with...

You could also use the predefined constant String.Empty.

By the way, 1.1 has been out for quite some time ...

Hans Kesting
Nov 17 '05 #3
I second this, use the constant String.Empty, instead of using a magic
value. It's just better practice.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Hans Kesting" <ne***********@ spamgourmet.com > wrote in message
news:eT******** ******@TK2MSFTN GP12.phx.gbl...
M D wrote:
You know how you assume you know until you find out you don't know.

Well, I typed into a function definition "..., new String("")).

I know what I want. Everyone reading this knows what I want.
However, the 1.0 compiler has no idea what I want.

Can anyone share with me the syntax that will actually communicate the
concept to the compiler, please?

thx
md

*** Sent via Developersdex http://www.developersdex.com ***


Why not use just "" ?
It's a bit of overkill to create a new string-object that you supply with
a string-literal (which is also a string-object) that has exactly the same
value as you want to end up with...

You could also use the predefined constant String.Empty.

By the way, 1.1 has been out for quite some time ...

Hans Kesting

Nov 17 '05 #4
M D
new String(): "No overload for method 'String' takes '0' arguments"

I need to create a new string on the heap for the top of a recursive
method. Wouldn't just foo(..., "") reference a constant on the string
table, ie an immutable object?

I haven't been given the VS.net version beyond the first, hence 1.0.

thx
md

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5
Hi M.D

if you really have to use a new instance of string, use:
string.Copy("")

but there really is no use of that other, than demonstrating the difference
of value and reference comparison.

Christof

"M D" <ma******@aol.c om> schrieb im Newsbeitrag
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
You know how you assume you know until you find out you don't know.

Well, I typed into a function definition "..., new String("")).

I know what I want. Everyone reading this knows what I want. However,
the 1.0 compiler has no idea what I want.

Can anyone share with me the syntax that will actually communicate the
concept to the compiler, please?

thx
md

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #6
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
I second this, use the constant String.Empty, instead of using a magic
value. It's just better practice.


In what way is it better practice than ""? They're both effectively
magic values in a way - it's not like using "foo" in two different
places, where you could accidentally change "foo" in one place but not
in another, but change the value in one place if you had it defined as
a constant. In this case, you'll never be able to change the value of
String.Empty anyway...

I've heard several people say that it *is* better to use String.Empty,
but never any believable reasons why. Personally I find "" more
readable.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7
Jon,

It really lends itself to maintaining discipline more than anything
else. In this case, I would say that there is a good arguement for "".
However, it is because of special conditions such as this that other
deviations from the practice become accepted. If there was actually a value
there, I am sure you would argue that a named constant should be used, for a
number of reasons. If the OP's value was subject to change, I would
actually recommend him using a named constant of his own (and not
String.Empty) and use that instead.

The interesting part about this is that I would not use a constant for
something such as 0 (when starting a loop) or 1 (for incrementing something
by one). Everyone has different tolerances, the empty string falls outside
of mine in this case.

For me, I just find it easier to adhere to an absolute rule instead of
having special cases (and admittedly, this is one of those cases where the
value isn't readily apparent). The more special cases you have, the more
you have to remember what they are, and the more subject your code is to
bugs.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
I second this, use the constant String.Empty, instead of using a
magic
value. It's just better practice.


In what way is it better practice than ""? They're both effectively
magic values in a way - it's not like using "foo" in two different
places, where you could accidentally change "foo" in one place but not
in another, but change the value in one place if you had it defined as
a constant. In this case, you'll never be able to change the value of
String.Empty anyway...

I've heard several people say that it *is* better to use String.Empty,
but never any believable reasons why. Personally I find "" more
readable.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #8
Well, it's a monir point, but "String.Emp ty" is easier to search for, if
you needed to find everyplace it's used (searching for "" would trip you up
with false positives on strings like : @"Who said ""Which way did he
go?""?";

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
I second this, use the constant String.Empty, instead of using a magic value. It's just better practice.


In what way is it better practice than ""? They're both effectively
magic values in a way - it's not like using "foo" in two different
places, where you could accidentally change "foo" in one place but not
in another, but change the value in one place if you had it defined as
a constant. In this case, you'll never be able to change the value of
String.Empty anyway...

I've heard several people say that it *is* better to use String.Empty,
but never any believable reasons why. Personally I find "" more
readable.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #9
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
It really lends itself to maintaining discipline more than anything
else. In this case, I would say that there is a good arguement for "".
However, it is because of special conditions such as this that other
deviations from the practice become accepted. If there was actually a value
there, I am sure you would argue that a named constant should be used, for a
number of reasons. If the OP's value was subject to change, I would
actually recommend him using a named constant of his own (and not
String.Empty) and use that instead.
Absolutely.
The interesting part about this is that I would not use a constant for
something such as 0 (when starting a loop) or 1 (for incrementing something
by one). Everyone has different tolerances, the empty string falls outside
of mine in this case.
That's fine - but I think it's then a matter of personal preference
rather than best practice.
For me, I just find it easier to adhere to an absolute rule instead of
having special cases (and admittedly, this is one of those cases where the
value isn't readily apparent). The more special cases you have, the more
you have to remember what they are, and the more subject your code is to
bugs.


I think it depends on the readability for me - "" is more readable than
String.Empty, and it's an easy enough single value to remember as an
exception to the rule.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #10

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

Similar topics

3
8888
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns a empty value instead of returning the browser type. Here is the line which i am using in my code and from manual: <?php echo $_SERVER; ?>
2
26673
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
4595
by: Dan Bass | last post by:
which one do you use and why? MyString == null || MyString == "" vs MyString == null || MyString.Length == 0
4
2344
by: web1110 | last post by:
I have an array of of 5 string elements. I put values in 3 of them. Yet when I loop over them, I do not catch the empty string. The code output below does not include "Empty" stringx=new String; x="111"; x="222"; x="333";
14
2335
by: cj | last post by:
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.
26
3796
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I test whether a string has a value or not by the following syntax: if (thisString.Trim() == "") {
26
2774
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.
35
3657
by: Smithers | last post by:
I have been told that it is a good idea to *always* declare string variables with a default value of string.Empty - for cases where an initial value is not known... like this: string myString = string.Empty; // do this string myString; // do not do this Questions 1. Is that a good rule? 2. If so, why? If not, why not?
2
14185
by: Jay | last post by:
I have a SQL Server table with nvarchar type column which has not null constraint. I am inserting empty string ("") from Java to the table column. When I export this table into .csv file using bcp tool, empty string gets written as NUL character. Is there any way I can bcp out empty string as empty string itself instead of NUL to the file? The bcp command I used to export table into csv file is bcp "SELECT...
21
2958
by: Sami | last post by:
string = "" or string = string.Empty? should is the proper way? Sami
0
8466
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8896
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...
1
8590
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
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...
1
6211
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
4208
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
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2798
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

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.