473,624 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's better then somestring=""

I understand that

If somestring.leng th = 0 Then

is faster then

If somestring = "" Then

and is equivalent to

If (somestring is Nothing) AndAlso (somestring = "") Then

Is that correct???

Also is there something better then:

somestring = ""

Thanks
Nov 21 '05 #1
15 1283
Hi,

There is string.empty
http://msdn.microsoft.com/library/de...emptytopic.asp

Ken
-----------------
" **Developer**" <RE************ *@a-znet.com> wrote in message
news:OE******** ******@tk2msftn gp13.phx.gbl...
I understand that

If somestring.leng th = 0 Then

is faster then

If somestring = "" Then

and is equivalent to

If (somestring is Nothing) AndAlso (somestring = "") Then

Is that correct???

Also is there something better then:

somestring = ""

Thanks

Nov 21 '05 #2
somestring = string.empty should be faster than using "", since anytime you
use double quotes, new string object is created in memory, but when you use
string.empty, you are comparing against a known constant.
" **Developer**" <RE************ *@a-znet.com> wrote in message
news:OE******** ******@tk2msftn gp13.phx.gbl...
I understand that

If somestring.leng th = 0 Then

is faster then

If somestring = "" Then

and is equivalent to

If (somestring is Nothing) AndAlso (somestring = "") Then

Is that correct???

Also is there something better then:

somestring = ""

Thanks

Nov 21 '05 #3
somestring = string.empty should be faster than using "", since anytime you
use double quotes, new string object is created in memory, but when you use
string.empty , you are comparing against a known constant.


No, you'll get the same empty string object in both cases. Try this

Dim s1 As String = ""
Dim s2 As String = ""
Console.WriteLi ne(s1 Is s2)
Console.WriteLi ne(s1 Is String.Empty)
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4
Developer,

In my idea is better not to think about performances got by this, it will
probably be something as 0,0000001 nanosecond and in the future even less.

You can in your live never win the time, that you did spent thinking about
it.

Just my idea

Cor
Nov 21 '05 #5
"Ken Tucker [MVP]" <vb***@bellsout h.net> schrieb:
There is string.empty
http://msdn.microsoft.com/library/de...emptytopic.asp


Yeah, but 'String.Empty' is the same as "" (a zero-length string). In terms
of readability I perfer "" over 'String.Empty'.

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

Nov 21 '05 #6
"Mattias Sjögren" <ma************ ********@mvps.o rg> schrieb:
somestring = string.empty should be faster than using "", since anytime
you
use double quotes, new string object is created in memory, but when you
use
string.empt y, you are comparing against a known constant.


No, you'll get the same empty string object in both cases. Try this

Dim s1 As String = ""
Dim s2 As String = ""
Console.WriteLi ne(s1 Is s2)
Console.WriteLi ne(s1 Is String.Empty)


That's true. The empty string is interned, and thus not duplicated:

\\\
MsgBox(String.I sInterned("") Is Nothing) ' False.
///

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

Nov 21 '05 #7
Herfried,

Yeah, but 'String.Empty' is the same as "" (a zero-length string). In
terms of readability I perfer "" over 'String.Empty'.

I prefer it because of typing

:-))

Cor
Nov 21 '05 #8
"Cor Ligthert [MVP]" <no************ @planet.nl> schrieb:
Yeah, but 'String.Empty' is the same as "" (a zero-length string). In
terms of readability I perfer "" over 'String.Empty'.

I prefer it because of typing

:-))


That's a valid reason too ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #9
" **Developer**" <RE************ *@a-znet.com> schrieb:
I understand that

If somestring.leng th = 0 Then

is faster then

If somestring = "" Then
There is a big difference between the two approaches. The first one will
crash with a 'NullReferenceE xception' if 'somestring' contains a
null-reference. The latter approach won't crash, it will simply return
'False' for the expression 'somestring = ""' because a reference to '""' is
not the same as a reference to 'Nothing'.
and is equivalent to

If (somestring is Nothing) AndAlso (somestring = "") Then

Is that correct???


No, that's not correct.

Personally I prefer to use the 'Len' function because it will return 0 as
length even for null-references:

\\\
Dim s As String = Nothing
MsgBox(Len(s)) ' 0.
s = ""
MsgBox(Len(s)) ' 0.
///

If you want an exception to be thrown for a null-reference, use the 'String'
object's 'Length' property.

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

Nov 21 '05 #10

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

Similar topics

6
1610
by: Tom Rahav | last post by:
Hi! I need to store some information about my application, such as trail version limits, allowed modules, etc. My question is whether it's better to store it in the windows registry, or in a binary file in the application's directory. My question is more aimed to the security issues, because I don't face performence as problem, since I need it just what the apllication starts. Thanks!
5
2758
by: Jarek | last post by:
Hi all! I'm optimizing my C++ multi-threaded application (linux). My application consumes huge amout of memory from unknown reason. There are no memory leaks, or other allocation bugs, application works well, but on startup it has about 200mb (VmSize). How can I investigate what function/class/other takes so much memory ? I tried to verify sizes of classes using sizeof, but it returns so small values (<100 bytes), there are very little...
1
1606
by: Alessandro Bottoni | last post by:
Is there any module or interface that allow the programmer to access a imap4/pop3 server in a more pythonic (or Object Oriented) way than the usual imaplib and popolib? I mean: is there any module that would allow me to query the server for specific messages (and fetch them) in a way similar to a OODB? TIA -----------------------------------
5
2071
by: junky_fellow | last post by:
Each time i submit some pattern to "google", it shows search took 0.XX seconds for exploring millions of web pages. When i look for efficient ways of searching a string, they always say compare your string with the strings in the file one by one. if there are millions of web pages then these algorithms would take considerable amount of time. So, what does google do for searching a pattern. Does it use thousands of parallel computers...
12
3222
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
9
4017
by: Dullme | last post by:
i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
5
3919
by: cowgurl art | last post by:
Hey there. I will not pretend to know more than I do...I'm just getting my feet wet with Dreamweaver and MySql databases. What I'm trying to do is create a form that will allow members to submit an audio file (mp3 or .wav) from a website. The form will insert the record into the database IF I can get it configured correctly. Here's the problem- I don't know what type to list the field as in order to get it to accept a file upload. Is this...
1
6923
by: CF FAN | last post by:
which one is better "eq" or "is" in coldfusion <cfif test eq "1"> or <cfif test is "1"> which one is more effective??
0
8251
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
8182
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
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8494
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
7178
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
5570
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
4085
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...
1
2614
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
1496
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.