473,385 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Hmm, What happened to Left ?

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


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
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
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
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
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
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
"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
"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
Herfried,

The why is in my messages in this thread

As well as the why not by the way

:-)

Cor
Nov 21 '05 #13
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Neil Zanella | last post by:
OK, this time the compiler's got me a little bit puzzled, simply because it is doing something I am not expecting. My understanding, according to the documentation of std::vector<>::resize(), is...
2
by: Lauren Wilson | last post by:
Hi folks, Just "upgraded" from A2K to A2K3. Everything is just hunky dory (so far) -- EXCEPT that the Add-in I had with A2K that auto inserts error code is no longer available in the Add-in...
2
by: N J | last post by:
Hi, Please take a look at http://webmonky.myby.co.uk/error.JPG . This is the second time this has happened. All I did was run command ... CurrentDb.Execute "Update tblDownload Set OrderType =...
1
by: Mikey | last post by:
Can somebody tell me what happened to the Source Profiler? It used to be under the Build menu in VC6, but now it's gone, and I cannot find anything in the docs that say what happened to it. The...
6
by: SugarDaddy | last post by:
I'm pretty new to C#, but I've had a lot of experience with MFC. MFC had a mechanism for updating dialog controls using an idle message. For those unfamiliar, basically you would override OnIdle...
0
by: han zhiyang | last post by:
I've just studied the "how to" web service and the async pattern in donnet.I make a test with these knowledges,but I got a strange result. Here is my test. 1.Write a simple "Add" service named...
7
by: Mike Rand | last post by:
I am having a really hard time trying to get some client side code hooked up in VS2005, ASP 2.0. The code is in an .inc file (vbscript). The first problem I am encountering is the ASP.NET page...
1
by: dkintheuk | last post by:
Hi all, Just had the wierdest thing happen overnight to one of my databases. I have a frontend/backend set up with the front end under development on my machine. I was copying a load of old...
3
by: Giampaolo Rodola' | last post by:
http://groups.google.com/group/python-dev2 It seems it no longer exists. What happened?
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.