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

Hmm, What happened to Left ?

P: n/a
Jm
Hi all

I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
18 Replies


P: n/a
String.SubString <--- That's what u got now !!

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Jm" <ja*****@ihug.com.au> wrote in message
news:cr**********@lust.ihug.co.nz...
Hi all

I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks

Nov 21 '05 #2

P: n/a
Jm
Ah thanks Sahil, a little different but easy to use nonetheless.

Thanks

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
String.SubString <--- That's what u got now !!

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Jm" <ja*****@ihug.com.au> wrote in message
news:cr**********@lust.ihug.co.nz...
Hi all

I feel stupid for asking this, but i just went to use the left() function from vb6 only to find it doesnt do what it used to under .NET. Im assuming theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks


Nov 21 '05 #3

P: n/a
Jm,

It is still there as a full continious part of the Net Framework, as well as
all these methods.

http://msdn.microsoft.com/library/de...rykeywords.asp

I hope this helps?

Cor

"Jm" <ja*****@ihug.com.au>
I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks

Nov 21 '05 #4

P: n/a


Microsoft.VisualBasic.Left()


--
Met vriendelijke groet
Kind regards,

Michel Posseth
Software Developer
Microsoft Certified Professional

Company : Nohau Systems B.V.
Division : Systems Development

"Jm" <ja*****@ihug.com.au> wrote in message
news:cr**********@lust.ihug.co.nz...
Hi all

I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks

Nov 21 '05 #5

P: n/a
Jim
"Jm" <ja*****@ihug.com.au> wrote in message
news:cr**********@lust.ihug.co.nz...
Hi all

I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks


In fact you can still use Left by invoking explicitly

Microsoft.VisualBasic.Left(string, length)

but this does seem a bit unneccesary now we have Substring.

Regards

--Jim.
Nov 21 '05 #6

P: n/a
Jm
Hi Cor

Thanks for the reply, i feel stupid saying it but i wasnt aware that
namespace existed. Sahil pointed out the new method which i used anyhow.
Thanks for the reply

Thanks

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
Jm,

It is still there as a full continious part of the Net Framework, as well as all these methods.

http://msdn.microsoft.com/library/de...rykeywords.asp
I hope this helps?

Cor

"Jm" <ja*****@ihug.com.au>
I feel stupid for asking this, but i just went to use the left() function from vb6 only to find it doesnt do what it used to under .NET. Im assuming theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks


Nov 21 '05 #7

P: n/a
Jm
Hi Jim

Thanks for the reply, i feel stupid saying it but i wasnt aware that
namespace existed. Sahil pointed out the new method which i used anyhow.
Thanks for the reply

Thanks
"Jim" <no******@this.address> wrote in message
news:2n**************@fe2.news.blueyonder.co.uk...
"Jm" <ja*****@ihug.com.au> wrote in message
news:cr**********@lust.ihug.co.nz...
Hi all

I feel stupid for asking this, but i just went to use the left() function from vb6 only to find it doesnt do what it used to under .NET. Im assuming theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks


In fact you can still use Left by invoking explicitly

Microsoft.VisualBasic.Left(string, length)

but this does seem a bit unneccesary now we have Substring.

Regards

--Jim.

Nov 21 '05 #8

P: n/a
JM,

That is not a new method, that is a very old method. It comes from the C
type languages.

The C type methods use a zero indexer and the VB type methods the First as
indexer.
I think it is good to stay to one kind because otherwise you will soon be
confused.

I never use methods which have a First as starting indexer although I think
it is better, the only reason for that is that I am used to that zero
indexer. (Therefore I use substring).

Cor

"Jm" <ja*****@ihug.com.au>

Hi Cor

Thanks for the reply, i feel stupid saying it but i wasnt aware that
namespace existed. Sahil pointed out the new method which i used anyhow.
Thanks for the reply

Thanks

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
Jm,

It is still there as a full continious part of the Net Framework, as well

as
all these methods.

http://msdn.microsoft.com/library/de...rykeywords.asp

I hope this helps?

Cor

"Jm" <ja*****@ihug.com.au>
> I feel stupid for asking this, but i just went to use the left() function > from vb6 only to find it doesnt do what it used to under .NET. Im assuming > theres something else now im meant to do when i want to say for example
>
> Dim Str as string
> Str = "1234"
> msgbox left(str,2)
>
> Thanks
>
>



Nov 21 '05 #9

P: n/a
http://mikecaldwell.com/VBNET.asp

Jm wrote:
Hi all

I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks


Nov 21 '05 #10

P: n/a
"Sahil Malik" <co*****************@nospam.com> schrieb:
String.SubString <--- That's what u got now !!


Why?! I am not a fan of weak semantics...

'Left' is still available in the 'Microsoft.VisualBasic.Strings' module and
is IMO the best choice.

To avoid a name clash with a form's 'Left' property, use 'Strings.Left' in
Windows Forms code.

--
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 #11

P: n/a
"Jim" <no******@this.address> schrieb:
In fact you can still use Left by invoking explicitly

Microsoft.VisualBasic.Left(string, length)

but this does seem a bit unneccesary now we have Substring.


Well, why not use pure assembler? 'Substring' is unnecessary too...

--
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 #12

P: n/a
Herfried,

The why is in my messages in this thread

As well as the why not by the way

:-)

Cor
Nov 21 '05 #13

P: n/a
Hefried,
Why?! I am not a fan of weak semantics... ?

How is String.SubString "weak semantics"? To me it is very OO, you have a
string object & you want to get part of that string object.

See my other post on using Strings.Left.

Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uE**************@TK2MSFTNGP09.phx.gbl... "Sahil Malik" <co*****************@nospam.com> schrieb:
String.SubString <--- That's what u got now !!


Why?! I am not a fan of weak semantics...

'Left' is still available in the 'Microsoft.VisualBasic.Strings' module
and is IMO the best choice.

To avoid a name clash with a form's 'Left' property, use 'Strings.Left' in
Windows Forms code.

--
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 #14

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

A Form has a Left property so it hides the VB.Left function, what I normally
do is use an Import Alias in my form source files to allow use of the
function.

Imports VB = Microsoft.VisualBasic

Public Class MainForm

...

Public Sub Test
Dim Str as string
Str = "1234"
msgbox VB.left(str,2)
End Class

A word of caution on String.SubString (System.String methods) & Strings.Left
(Microsoft.VisualBasic.Strings functions): System.String methods uses base 0
indexes while Microsoft.VisualBasic.Strings uses base 1 indexes. I would
recommend you stay with either the System.String methods or the
Microsoft.VisualBasic.Strings functions to avoid possible confusion & subtle
problems later...

Hope this helps
Jay

"Jm" <ja*****@ihug.com.au> wrote in message
news:cr**********@lust.ihug.co.nz... Hi all

I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks

Nov 21 '05 #15

P: n/a
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
Why?! I am not a fan of weak semantics...

?

How is String.SubString "weak semantics"? To me it is very OO, you have a
string object & you want to get part of that string object.


'Left', 'Mid' and 'Right' make it more obvious which part of the string is
returned, and thus make code more readable. 'Substring' can be used to to
the same, but the user will have to analyze the values passed to it in order
to be able to determine if the left, right, or an arbitrary part (middle) of
the string is returned. In other words: The name 'Substring' only tells
the reader that a part of the string is returned, names like 'Left' and
'Right' provide more/additional information.

Notice that I was not discussing that 'Substring' is more OO than 'Left',
'Right', etc. OO is a good tool, but in some cases (like working with
strings or dealing with numbers) it IMO doesn't add much benefit.

Would

\\\
Dim d As Double = ...
Dim e As Double = d.Cos() * 2
///

really have benefits over

\\\
Dim d As Double
Dim e As Double = Math.Cos(d) * 2
///

only because it's more OO?

SCNR

--
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 #16

P: n/a
Herfried,
'Left', 'Mid' and 'Right' make it more obvious which part of the string is
returned, and thus make code more readable. I agree it may be more obvious...

However! I'm just wondering about "weak semantics", to me saying it is "weak
semantics" is like insisting a glass is half full, when it is obvious it is
really half empty! Considering most of the time, it really doesn't matter if
I am getting the Left, Mid or Right of a string, I just want a part of the
string...

When you just want part of a string, any part of the string, SubString or
just Mid is sufficient. Left & Right can be implemented in terms of
SubString or Mid themselves...
the same, but the user will have to analyze the values passed to it in
order to be able to determine if the left, right, or an arbitrary part
(middle) of the string is returned. If one uses SubString enough is this really an issue? In other words, they
soon pick up on:
- x.SubString(0, n) is Left
- x.SubString(n) is Right (not the same as VB.Right!)
- x.SubString(m,n) is Middle

Which if you believe Overloading is "evil", then yes I agree it may be "weak
semantics". However! I see overloading as a very powerful OO tool (which
like any construct can be easily abused), so the above does not cause me any
real issues... Info on "Overloading vs. Object Technology"
http://www.inf.ethz.ch/personal/meye...verloading.pdf

I do find VB.Left, VB.Right, & VB.Mid can be "better" in that they have more
tolerant argument checking, which also makes String.SubString "better" as it
insists on correct arguments!

Jay

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

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
Why?! I am not a fan of weak semantics...

?

How is String.SubString "weak semantics"? To me it is very OO, you have a
string object & you want to get part of that string object.


'Left', 'Mid' and 'Right' make it more obvious which part of the string is
returned, and thus make code more readable. 'Substring' can be used to to
the same, but the user will have to analyze the values passed to it in
order to be able to determine if the left, right, or an arbitrary part
(middle) of the string is returned. In other words: The name 'Substring'
only tells the reader that a part of the string is returned, names like
'Left' and 'Right' provide more/additional information.

Notice that I was not discussing that 'Substring' is more OO than 'Left',
'Right', etc. OO is a good tool, but in some cases (like working with
strings or dealing with numbers) it IMO doesn't add much benefit.

Would

\\\
Dim d As Double = ...
Dim e As Double = d.Cos() * 2
///

really have benefits over

\\\
Dim d As Double
Dim e As Double = Math.Cos(d) * 2
///

only because it's more OO?

SCNR

--
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 #17

P: n/a
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
'Left', 'Mid' and 'Right' make it more obvious which part of the string
is returned, and thus make code more readable. I agree it may be more obvious...

However! I'm just wondering about "weak semantics", to me saying it is
"weak semantics" is like insisting a glass is half full, when it is
obvious it is really half empty! Considering most of the time, it really
doesn't matter if I am getting the Left, Mid or Right of a string, I just
want a part of the string...


When learning string algorithms for university, I found those much clearer
and easier to understand which used 'Left' or 'Right' instead of picking out
a part of a string starting at a certain position and ending at a certain
position, or starting at a certain position and being of a certain length,
respectively. Imagine describing an algorithm that works on a string to
somebody via telephone. Would you say "Take the substring starting at
position 22 and ending at the string's end" or would you say "Take the
string's last three characters". I'd say the latter. Sure, taking the
start and end of a string /is/ taking /part of/ the string, but that's a
more general description of what is done.
When you just want part of a string, any part of the string, SubString or
just Mid is sufficient. Left & Right can be implemented in terms of
SubString or Mid themselves...
If I just want a part of the string that I don't have more information
about, I use 'Mid'. For the special cases, I prefer 'Right' and 'Left' for
the reasons described above.
the same, but the user will have to analyze the values passed to it in
order to be able to determine if the left, right, or an arbitrary part
(middle) of the string is returned.


If one uses SubString enough is this really an issue? In other words, they
soon pick up on:
- x.SubString(0, n) is Left
- x.SubString(n) is Right (not the same as VB.Right!)
- x.SubString(m,n) is Middle


You definitely /can/ get used to it and then be able to use it without any
problems.

BTW: It's interesting that the method's name is 'Substring', but most
people refer to it as 'SubString', even those who are using case-sensitive
programming languages ;-).
Which if you believe Overloading is "evil", then yes I agree it may be
"weak semantics". However! I see overloading as a very powerful OO tool
(which like any construct can be easily abused), so the above does not
cause me any real issues... Info on "Overloading vs. Object Technology"
http://www.inf.ethz.ch/personal/meye...verloading.pdf
Thanks for the link, that's an interesting article. Well, I really liked
the sample of named constructors the author of the article you referenced
above gave... ;-). I believe in the power of overloading and I am confident
that it is a very powerful OO tool, but my concerns were not primarily
related to overloading in general.
I do find VB.Left, VB.Right, & VB.Mid can be "better" in that they have
more tolerant argument checking, which also makes String.SubString
"better" as it insists on correct arguments!


:-)

--
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 #18

P: n/a
Herfried,
BTW: It's interesting that the method's name is 'Substring', but most
people refer to it as 'SubString', even those who are using case-sensitive
programming languages ;-). I was using Substring (in this thread), but I "corrected" myself, as
SubString was used earlier in this thread...

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

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
'Left', 'Mid' and 'Right' make it more obvious which part of the string
is returned, and thus make code more readable.

I agree it may be more obvious...

However! I'm just wondering about "weak semantics", to me saying it is
"weak semantics" is like insisting a glass is half full, when it is
obvious it is really half empty! Considering most of the time, it really
doesn't matter if I am getting the Left, Mid or Right of a string, I just
want a part of the string...


When learning string algorithms for university, I found those much clearer
and easier to understand which used 'Left' or 'Right' instead of picking
out a part of a string starting at a certain position and ending at a
certain position, or starting at a certain position and being of a certain
length, respectively. Imagine describing an algorithm that works on a
string to somebody via telephone. Would you say "Take the substring
starting at position 22 and ending at the string's end" or would you say
"Take the string's last three characters". I'd say the latter. Sure,
taking the start and end of a string /is/ taking /part of/ the string, but
that's a more general description of what is done.
When you just want part of a string, any part of the string, SubString or
just Mid is sufficient. Left & Right can be implemented in terms of
SubString or Mid themselves...


If I just want a part of the string that I don't have more information
about, I use 'Mid'. For the special cases, I prefer 'Right' and 'Left'
for the reasons described above.
the same, but the user will have to analyze the values passed to it in
order to be able to determine if the left, right, or an arbitrary part
(middle) of the string is returned.


If one uses SubString enough is this really an issue? In other words,
they soon pick up on:
- x.SubString(0, n) is Left
- x.SubString(n) is Right (not the same as VB.Right!)
- x.SubString(m,n) is Middle


You definitely /can/ get used to it and then be able to use it without any
problems.

BTW: It's interesting that the method's name is 'Substring', but most
people refer to it as 'SubString', even those who are using case-sensitive
programming languages ;-).
Which if you believe Overloading is "evil", then yes I agree it may be
"weak semantics". However! I see overloading as a very powerful OO tool
(which like any construct can be easily abused), so the above does not
cause me any real issues... Info on "Overloading vs. Object Technology"
http://www.inf.ethz.ch/personal/meye...verloading.pdf


Thanks for the link, that's an interesting article. Well, I really liked
the sample of named constructors the author of the article you referenced
above gave... ;-). I believe in the power of overloading and I am
confident that it is a very powerful OO tool, but my concerns were not
primarily related to overloading in general.
I do find VB.Left, VB.Right, & VB.Mid can be "better" in that they have
more tolerant argument checking, which also makes String.SubString
"better" as it insists on correct arguments!


:-)

--
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 #19

This discussion thread is closed

Replies have been disabled for this discussion.