Home All Groups Group Topic Archive Search About
Author
27 Mar 2006 2:11 PM
rodchar
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

Author
27 Mar 2006 2:53 PM
Claes Bergefall
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

Show quoteHide quote
"rodchar" <rodc***@discussions.microsoft.com> wrote in message
news:A5498591-3108-46C9-87A8-35A584013FB3@microsoft.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
Author
27 Mar 2006 3:34 PM
Cor Ligthert [MVP]
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

Show quoteHide quote
"rodchar" <rodc***@discussions.microsoft.com> schreef in bericht
news:A5498591-3108-46C9-87A8-35A584013FB3@microsoft.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
Author
27 Mar 2006 5:18 PM
Rocky
The second one is faster by about 50%.

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




Show quoteHide quote
"rodchar" <rodc***@discussions.microsoft.com> wrote in message
news:A5498591-3108-46C9-87A8-35A584013FB3@microsoft.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
Author
27 Mar 2006 7:59 PM
Herfried K. Wagner [MVP]
"rodchar" <rodc***@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/>
Author
28 Mar 2006 1:19 AM
Jay B. Harlow [MVP - Outlook]
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


Show quoteHide quote
"rodchar" <rodc***@discussions.microsoft.com> wrote in message
news:A5498591-3108-46C9-87A8-35A584013FB3@microsoft.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
Author
28 Mar 2006 1:41 AM
rodchar
thanks everyone for the great help.
rc

Show quoteHide quote
"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