By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,065 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,065 IT Pros & Developers. It's quick & easy.

which is better

P: n/a
hey all,

is there a difference when saying:

myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)

-or

myArrary = Split(_dr.TCADR1, " ")
myString = myArray(0) & " " & myArray(1)

thanks,
rodchar
Mar 27 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I'd say that there is a performance hit with the first, since it's doing 2
method calls. You'll hardly notice it though (unless you do it a *lot*) so
go with whatever feels best.

/claes

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
hey all,

is there a difference when saying:

myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)

-or

myArrary = Split(_dr.TCADR1, " ")
myString = myArray(0) & " " & myArray(1)

thanks,
rodchar

Mar 27 '06 #2

P: n/a
Rodchar,

In my opinion is the second the most optimized. It reads easier.

However the slight performance benefit will be as well with the second.

You need in the second only one split command to be executed, in the first
that is two.

Just my thought,

Cor

"rodchar" <ro*****@discussions.microsoft.com> schreef in bericht
news:A5**********************************@microsof t.com...
hey all,

is there a difference when saying:

myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)

-or

myArrary = Split(_dr.TCADR1, " ")
myString = myArray(0) & " " & myArray(1)

thanks,
rodchar

Mar 27 '06 #3

P: n/a
The second one is faster by about 50%.

But this is faster by roughly 68%.
ar = str.Split(" "c)
result = ar(0) & " " & ar(1)


"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
hey all,

is there a difference when saying:

myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)

-or

myArrary = Split(_dr.TCADR1, " ")
myString = myArray(0) & " " & myArray(1)

thanks,
rodchar

Mar 27 '06 #4

P: n/a
"rodchar" <ro*****@discussions.microsoft.com> schrieb:
is there a difference when saying:

myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)

-or

myArrary = Split(_dr.TCADR1, " ")
myString = myArray(0) & " " & myArray(1)


I suggest to choose the second option because it won't perform a useless
'Split' operation.

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

Mar 27 '06 #5

P: n/a
rodchar,
In addition to the other comments.

| is there a difference when saying:
To the computer, no there is no real difference. Although you are calling
Split twice which may have a minor impact on performance speed & GC
pressure. Unless the statement is in a tight loop, I would expect the
performance impact & GC pressure to be relatively minor...
More importantly: To humans (including yourself in 6 months) there is a huge
difference!

I would expect most developers would find the second to be more immediately
obvious what you are trying to do, in other words the "intent of the code".
While the first reading the code one has to stop & think about what's
happening...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
| hey all,
|
| is there a difference when saying:
|
| myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)
|
| -or
|
| myArrary = Split(_dr.TCADR1, " ")
| myString = myArray(0) & " " & myArray(1)
|
| thanks,
| rodchar
Mar 28 '06 #6

P: n/a
thanks everyone for the great help.
rc

"rodchar" wrote:
hey all,

is there a difference when saying:

myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)

-or

myArrary = Split(_dr.TCADR1, " ")
myString = myArray(0) & " " & myArray(1)

thanks,
rodchar

Mar 28 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.