473,657 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Meaning of "[string]"

I'm using some sample code from MSDN. The code includes the following
statement:

Dim content as [String] = [String].Empty

I'm not familiar with the use of the square brackets. Can someone please
explain to me what the difference between "Dim content as [String]" and
"Dim content as String". Thanks.

Peter,

--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com
Nov 21 '05 #1
8 4852
I've seen square brackets used to allow variable names that match keywords,
but your example is definately odd.

Dim [String] As String = String.Empty

Greg

"Peter Merwood" <pe*****@circ le-consulting.co.n z> wrote in message
news:ey******** ******@TK2MSFTN GP09.phx.gbl...
I'm using some sample code from MSDN. The code includes the following
statement:

Dim content as [String] = [String].Empty

I'm not familiar with the use of the square brackets. Can someone please
explain to me what the difference between "Dim content as [String]" and
"Dim content as String". Thanks.

Peter,

--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com

Nov 21 '05 #2
Peter,

In the beginning of VBNet where most samples on MSDN translated C# or
translated VB classic ones. This becomes better and better, however there
are still some odd ones. And as Greg stated already this is one of them.
(You are not the first one who ask this question about that sample)
Dim content as [String] = [String].Empty
This sample would imply that you have created your own class with the name
[String] and because there is already a String class, that would be
ambigious and you use the brackets to tell to use your own class.

As well it tells that you have created somewhere your own shared
String.Empty methode and for that obtains the same rules as above.

Only a lunatic will do that.

I hope this explains it something?

Cor
"Peter Merwood" <pe*****@circ le-consulting.co.n z>

I'm using some sample code from MSDN. The code includes the following
statement:

Dim content as [String] = [String].Empty

I'm not familiar with the use of the square brackets. Can someone please
explain to me what the difference between "Dim content as [String]" and
"Dim content as String". Thanks.

Peter,

--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com

Nov 21 '05 #3
Cor

Thanks for the explanation. It all becomes clear now.

I'm not a "lunatic" (!) and I don't have any objects in my project named
"String". Therefore I'll change "Dim content as [String] = [String].Empty"
to "Dim content as String".

The use of the String.Empty initial value by MS is also a bit dumb - aren't
all strings empty by default when they're initialised?

Thanks again.

Peter
--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:ez******** *****@TK2MSFTNG P15.phx.gbl...
Peter,

In the beginning of VBNet where most samples on MSDN translated C# or
translated VB classic ones. This becomes better and better, however there
are still some odd ones. And as Greg stated already this is one of them.
(You are not the first one who ask this question about that sample)
Dim content as [String] = [String].Empty


This sample would imply that you have created your own class with the name
[String] and because there is already a String class, that would be
ambigious and you use the brackets to tell to use your own class.

As well it tells that you have created somewhere your own shared
String.Empty methode and for that obtains the same rules as above.

Only a lunatic will do that.

I hope this explains it something?

Cor
"Peter Merwood" <pe*****@circ le-consulting.co.n z>

I'm using some sample code from MSDN. The code includes the following
statement:

Dim content as [String] = [String].Empty

I'm not familiar with the use of the square brackets. Can someone please explain to me what the difference between "Dim content as [String]" and
"Dim content as String". Thanks.

Peter,

--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com


Nov 21 '05 #4
Peter,
The use of the String.Empty initial value by MS is also a bit dumb -
aren't
all strings empty by default when they're initialised?
As you said, however there is a slight difference the String is an forever
confusing value what can be an object.

With the String you have this
\\\
dim content as string
///
Gives with
If content Is Nothing then messagebox.show ("true")
true
While
dim content as string = "" (what is a constant) does not give that.

They both give
If content = Nothing then messagebox.show ("true")
true

There is a lot written in this newsgroup about this, so maybe you can google
this newsgroup for that when you want to know more.

However, I hope this gives some idea's?

Cor

"Peter Merwood"
Cor

Thanks for the explanation. It all becomes clear now.

I'm not a "lunatic" (!) and I don't have any objects in my project named
"String". Therefore I'll change "Dim content as [String] =
[String].Empty"
to "Dim content as String".

The use of the String.Empty initial value by MS is also a bit dumb -
aren't
all strings empty by default when they're initialised?

Thanks again.

Peter
--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:ez******** *****@TK2MSFTNG P15.phx.gbl...
Peter,

In the beginning of VBNet where most samples on MSDN translated C# or
translated VB classic ones. This becomes better and better, however there
are still some odd ones. And as Greg stated already this is one of them.
(You are not the first one who ask this question about that sample)
>Dim content as [String] = [String].Empty


This sample would imply that you have created your own class with the
name
[String] and because there is already a String class, that would be
ambigious and you use the brackets to tell to use your own class.

As well it tells that you have created somewhere your own shared
String.Empty methode and for that obtains the same rules as above.

Only a lunatic will do that.

I hope this explains it something?

Cor
"Peter Merwood" <pe*****@circ le-consulting.co.n z>

> I'm using some sample code from MSDN. The code includes the following
> statement:
>
> Dim content as [String] = [String].Empty
>
> I'm not familiar with the use of the square brackets. Can someone please > explain to me what the difference between "Dim content as [String]"
> and
> "Dim content as String". Thanks.
>
> Peter,
>
> --
>
>
> ----------------------------------------------------
> This mailbox protected from junk email by MailFrontier Desktop
> from MailFrontier, Inc. http://info.mailfrontier.com
>
>



Nov 21 '05 #5
"Peter Merwood" <pe*****@circ le-consulting.co.n z> schrieb:
Dim content as [String] = [String].Empty

I'm not familiar with the use of the square brackets. Can someone please
explain to me what the difference between "Dim content as [String]" and
"Dim content as String".


The square brackets are documented here:

<URL:http://msdn.microsoft. com/library/en-us/vbls7/html/vblrfVBSpec2_2. asp>

In the sample code you showed above, square brackets don't make much sense.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
Peter,
The use of the String.Empty initial value by MS is also a bit dumb -
aren't
all strings empty by default when they're initialised? No, all strings are Nothing by default when they're initialized.

In addition to Cor's example. Try the following:

Dim content As String
If content.Length = 0 Then
' Never gets here
' as an NullReferenceEx ception was raised!
End IF

VB considers a String variable that is Nothing and a String variable that
has String.Empty in it as equal.

Hope this helps
Jay

"Peter Merwood" <pe*****@circ le-consulting.co.n z> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. Cor

Thanks for the explanation. It all becomes clear now.

I'm not a "lunatic" (!) and I don't have any objects in my project named
"String". Therefore I'll change "Dim content as [String] =
[String].Empty"
to "Dim content as String".

The use of the String.Empty initial value by MS is also a bit dumb -
aren't
all strings empty by default when they're initialised?

Thanks again.

Peter
--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:ez******** *****@TK2MSFTNG P15.phx.gbl...
Peter,

In the beginning of VBNet where most samples on MSDN translated C# or
translated VB classic ones. This becomes better and better, however there
are still some odd ones. And as Greg stated already this is one of them.
(You are not the first one who ask this question about that sample)
>Dim content as [String] = [String].Empty


This sample would imply that you have created your own class with the
name
[String] and because there is already a String class, that would be
ambigious and you use the brackets to tell to use your own class.

As well it tells that you have created somewhere your own shared
String.Empty methode and for that obtains the same rules as above.

Only a lunatic will do that.

I hope this explains it something?

Cor
"Peter Merwood" <pe*****@circ le-consulting.co.n z>

> I'm using some sample code from MSDN. The code includes the following
> statement:
>
> Dim content as [String] = [String].Empty
>
> I'm not familiar with the use of the square brackets. Can someone please > explain to me what the difference between "Dim content as [String]"
> and
> "Dim content as String". Thanks.
>
> Peter,
>
> --
>
>
> ----------------------------------------------------
> This mailbox protected from junk email by MailFrontier Desktop
> from MailFrontier, Inc. http://info.mailfrontier.com
>
>



Nov 21 '05 #7
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb:
The use of the String.Empty initial value by MS is also a bit dumb -
aren't
all strings empty by default when they're initialised?
No, all strings are Nothing by default when they're initialized.


That's true. Strings are initialized with 'Nothing', not 'String.Empty'.
In addition to Cor's example. Try the following:

Dim content As String
If content.Length = 0 Then
' Never gets here
' as an NullReferenceEx ception was raised!
End IF

VB considers a String variable that is Nothing and a String variable that
has String.Empty in it as equal.


Just to make sure that this is not misread: The code above won't throw an
exception if 'String.Empty' was assigned to 'content'. If this was the
case, 'content.Length ' would return 0.

What VB does is considering a string variable that points to 'Nothing' and a
string variable that has 'String.Empty' in it as equal when comparing these
string variables using '=':

\\\
Dim s1 As String
Dim s2 As String = String.Empty
MsgBox(CStr(s1 = s2)) ' 'True'.
///

.... and...

\\\
Dim s1 As String
Dim s2 As String = String.Empty
MsgBox(CStr(s1 Is s2)) ' 'False'.
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #8
Herfried,
Just to make sure that this is not misread: The code above won't throw an
exception if 'String.Empty' was assigned to 'content'. If this was the
case, 'content.Length ' would return 0. Correct, I intentionally left off the initialization of the variable
"content", so it was initialized to its "default" value of Nothing.

Thanks for the additional.

Jay
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:uD******** ******@TK2MSFTN GP09.phx.gbl... Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb:
The use of the String.Empty initial value by MS is also a bit dumb -
aren't
all strings empty by default when they're initialised?


No, all strings are Nothing by default when they're initialized.


That's true. Strings are initialized with 'Nothing', not 'String.Empty'.
In addition to Cor's example. Try the following:

Dim content As String
If content.Length = 0 Then
' Never gets here
' as an NullReferenceEx ception was raised!
End IF

VB considers a String variable that is Nothing and a String variable that
has String.Empty in it as equal.


Just to make sure that this is not misread: The code above won't throw an
exception if 'String.Empty' was assigned to 'content'. If this was the
case, 'content.Length ' would return 0.

What VB does is considering a string variable that points to 'Nothing' and
a string variable that has 'String.Empty' in it as equal when comparing
these string variables using '=':

\\\
Dim s1 As String
Dim s2 As String = String.Empty
MsgBox(CStr(s1 = s2)) ' 'True'.
///

... and...

\\\
Dim s1 As String
Dim s2 As String = String.Empty
MsgBox(CStr(s1 Is s2)) ' 'False'.
///

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

Nov 21 '05 #9

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

Similar topics

1
149718
by: Robin Tucker | last post by:
Hi, I would like to select records from a table where the following criteria hold: SELECT * from Mytable where field x "contains" string @X or
32
2679
by: Indrid Colt | last post by:
Thank's for your help ! Indrid
16
3762
by: ondekoza | last post by:
Hello, I need to convert the string "FFFFFFFF" to a long. To convert this string I tried the following: >>> 0xffffffff -1 >>> 0xffffffffL 4294967295L OK, this is what I want, so I tried
35
75171
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
9
3774
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in code. for example, this is bad practice: header.h #include <string> using std::string;
2
11001
by: excite | last post by:
I am trying to write a long string into a txt file, the string includes some backslash, looks like: 'd:\#########\#######\####### d:\######\####\####\### d:\###\###\' then I got a error saying 'EOL while scanning single-quoted string'. But it works when I just delete the last backslash or add one more backslash in the end. Can someone tell me what is the meaning of this error, and how to handle this problem? Thanks.
17
5253
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
10
9051
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use std::string::size or std::string::empty to deal with this condition? Thank you. string s = ""; if (s == ""); if (s.size == 0); if (s.empty());
1
12318
by: mato81 | last post by:
Hi all! I am a newbie to WSDL. I have a questions which has been driving me crazy... If I would have a WSDL with a types element somewhat like below, what is the point of the third last row "<s:element name="string" nillable="true" type="s:string"/>". Why is it there and what is it for? ... <wsdl:types> <s:schema elementFormDefault="qualified" targetNamespace="http://www.home.NET"> <s:element name="GetWeather">
0
8825
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
8605
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
7324
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...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
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
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
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.