473,408 Members | 1,976 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,408 software developers and data experts.

Empty Character Literal

VJ

I have a property for a control ( source code not available) . The property
accepts single char as value.. so I can set it to '/' or ':' or anything
like that...At initialize of my From I want this property to be set to a
empty literal. I am able to do this at design time using VS.NET property
box. This works for controls created at design time, but for some controls I
create at run-time I want to do the same at Form_load..

VJ

Nov 17 '05 #1
9 119225
There is no "empty character literal", because every possible value
for a char type is one character long. You can have zero length
strings ("") but not zero-length characters, e.g. this will not
compile:

char ch = ''; // doesn't work

The closest you can get is a space (' ') or a null character ('\0',
ASCII zero).

P.
Nov 17 '05 #2
VJ <vi********@yahoo.com> wrote:
I have a property for a control ( source code not available) . The property
accepts single char as value.. so I can set it to '/' or ':' or anything
like that...At initialize of my From I want this property to be set to a
empty literal. I am able to do this at design time using VS.NET property
box. This works for controls created at design time, but for some controls I
create at run-time I want to do the same at Form_load..


There's no such thing as an "empty" character, any more than there's an
"empty integer". What's the property used for? Character 0 (the "null"
character) *might* be an appropriate start value, but it's hard to say
without more information.

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

"VJ" <vi********@yahoo.com> schrieb im Newsbeitrag
news:uP*************@TK2MSFTNGP10.phx.gbl...

I have a property for a control ( source code not available) . The
property accepts single char as value.. so I can set it to '/' or ':' or
anything like that...At initialize of my From I want this property to be
set to a empty literal. I am able to do this at design time using VS.NET
property box. This works for controls created at design time, but for some
controls I create at run-time I want to do the same at Form_load..

VJ

If you can do it with VS.NET, simply do it and check the value while
runtime.
The you know, what character it is and set it in code.
Nov 17 '05 #4
Just a technical note about this: The reason that you can have empty strings
is that a string is an array of char with a null terminator. That is, a
string is actually (in memory) one char longer than the actual string,
including the null terminator. A char, on the other hand, is not an array,
but a single char.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Paul E Collins" <fi******************@CL4.org> wrote in message
news:di**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
There is no "empty character literal", because every possible value for a
char type is one character long. You can have zero length strings ("") but
not zero-length characters, e.g. this will not compile:

char ch = ''; // doesn't work

The closest you can get is a space (' ') or a null character ('\0', ASCII
zero).

P.

Nov 17 '05 #5
that is not true.

..net strings are not null terminated. the reason why you can have an
empty string is because it's perfectly legal to have a 0-length array.

Kevin Spencer wrote:
Just a technical note about this: The reason that you can have empty strings
is that a string is an array of char with a null terminator. That is, a
string is actually (in memory) one char longer than the actual string,
including the null terminator. A char, on the other hand, is not an array,
but a single char.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Paul E Collins" <fi******************@CL4.org> wrote in message
news:di**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
There is no "empty character literal", because every possible value for a
char type is one character long. You can have zero length strings ("") but
not zero-length characters, e.g. this will not compile:

char ch = ''; // doesn't work

The closest you can get is a space (' ') or a null character ('\0', ASCII
zero).

P.


Nov 17 '05 #6
VJ
Ok I got this one... The property had a corresponding Int property which if
I set to zero then it achieved the same thing as setting to nothing using
VS.NET property window...

Thanks all for your input..
VJ

"VJ" <vi********@yahoo.com> wrote in message
news:uP*************@TK2MSFTNGP10.phx.gbl...

I have a property for a control ( source code not available) . The
property accepts single char as value.. so I can set it to '/' or ':' or
anything like that...At initialize of my From I want this property to be
set to a empty literal. I am able to do this at design time using VS.NET
property box. This works for controls created at design time, but for some
controls I create at run-time I want to do the same at Form_load..

VJ

Nov 17 '05 #7
Well, Daniel, you made me do my homework. In fact, we were both wrong. The
truth is a bit more complex. It depends on the implementation used. If C# or
C++ is used, it is indeed an array of WCHAR. If C is used, it is a
null-terminated string.

Now for some aspirin...

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Daniel Jin" <sh********@yahoo.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
that is not true.

.net strings are not null terminated. the reason why you can have an
empty string is because it's perfectly legal to have a 0-length array.

Kevin Spencer wrote:
Just a technical note about this: The reason that you can have empty
strings
is that a string is an array of char with a null terminator. That is, a
string is actually (in memory) one char longer than the actual string,
including the null terminator. A char, on the other hand, is not an
array,
but a single char.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Paul E Collins" <fi******************@CL4.org> wrote in message
news:di**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
> There is no "empty character literal", because every possible value for
> a
> char type is one character long. You can have zero length strings ("")
> but
> not zero-length characters, e.g. this will not compile:
>
> char ch = ''; // doesn't work
>
> The closest you can get is a space (' ') or a null character ('\0',
> ASCII
> zero).
>
> P.
>
>

Nov 17 '05 #8
I'm not sure what you mean by "depends on implemenation". according to Jon
Skeet's article on .NET string though, it is indeed null terminated
internally for p/invoke. so I was wrong, which makes my original point a
little inconsequential, that you don't need null termination for empty
strings, a 0-length array should do just fine.

"Kevin Spencer" wrote:
Well, Daniel, you made me do my homework. In fact, we were both wrong. The
truth is a bit more complex. It depends on the implementation used. If C# or
C++ is used, it is indeed an array of WCHAR. If C is used, it is a
null-terminated string.

Now for some aspirin...

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Daniel Jin" <sh********@yahoo.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
that is not true.

.net strings are not null terminated. the reason why you can have an
empty string is because it's perfectly legal to have a 0-length array.

Kevin Spencer wrote:
Just a technical note about this: The reason that you can have empty
strings
is that a string is an array of char with a null terminator. That is, a
string is actually (in memory) one char longer than the actual string,
including the null terminator. A char, on the other hand, is not an
array,
but a single char.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Paul E Collins" <fi******************@CL4.org> wrote in message
news:di**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
> There is no "empty character literal", because every possible value for
> a
> char type is one character long. You can have zero length strings ("")
> but
> not zero-length characters, e.g. this will not compile:
>
> char ch = ''; // doesn't work
>
> The closest you can get is a space (' ') or a null character ('\0',
> ASCII
> zero).
>
> P.
>
>


Nov 17 '05 #9
By the way, just for your information C# 2.0 has the concept of
nullable types. There is still no such thing as the "empty character",
but in C# 2.0 you can say:

char? emptyChar = null;

which isn't quite what you were after, but I thought I'd mention it
because it's sort of related. :)

Nov 17 '05 #10

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

Similar topics

9
by: Christian Kandeler | last post by:
Hi, if I want to store the string "123456" in a variable of type char, I can do it like this: char s = "123456"; Or like this: char s = { '1', '2', '3', '4', '5', '6', '\0' };
4
by: Dakkar | last post by:
when i write something like this char arr = {'a','b','''} its giving the Error 2 Empty character literal error how can i add the ' character to an char array...
3
by: Eranga | last post by:
What is empty character literal and how can we get rid of it. I want to check whether the text box is empty so I use if (TextBox1.Text == '' ) Why cant I do this? *** Sent via Developersdex...
9
by: gvanosdol | last post by:
When on my development machine, I can execute the code in the subject (string strVarArr = strVar.Split('x');) without any problems. When I try to move the code to my server, I get "CS1011: Empty...
13
by: Ivan | last post by:
Hi, What is the best syntax to use a char to index into an array. /////////////////////////////////// For example int data; data = 1;
21
by: Sami | last post by:
string = "" or string = string.Empty? should is the proper way? Sami
6
by: =?ISO-8859-2?Q?Boris_Du=B9ek?= | last post by:
Hi, I have trouble defining a macro - see the following code: #define LETTER_STRAIGHT(let) let = L'#let' enum Letter { LETTER_STRAIGHT(A), LETTER_STRAIGHT(B), LETTER_STRAIGHT(C),
4
by: zaimoni | last post by:
I've already calculated that the following are valid and should not error, as both just end up with the character literal 'A' being their control expression. The unspecified value of the char*...
2
by: zman77 | last post by:
Hello, I have a bunch of Image Buttons in my code. When I leave them as they are, I can build my project without problems. However, when I add OnClick to an image button, I get the error: Too...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
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...
0
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...

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.