473,387 Members | 1,687 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,387 software developers and data experts.

Left, Right and Mid

A.M
Hi,

Using C#, what is the equivalent of functions Left, Right and Mid that we
had in vb6?

Thanks,
Alan
Nov 16 '05 #1
8 38601
left is MyString.SubString(0,length)
mid is MyString.SubString(start, length)
right is MyString.SubString(MyString.Length - length)

--
Michael Culley
"A.M" <IH*******@sapm123.com> wrote in message news:uM**************@TK2MSFTNGP09.phx.gbl...
Hi,

Using C#, what is the equivalent of functions Left, Right and Mid that we
had in vb6?

Thanks,
Alan

Nov 16 '05 #2
string myString = "My String";
Left: myString.Substring(0, 4); // Left 4 characters
Right: myString.Substring(myString.Length - 4); // Right 4 characters
Mid: myString.Substring(startIndex); // Mid overload 1
Mid: myString.Substring(startIndex, count); // Mid overload 2

Mid has optional parameters, so these act as overloads in C#. The Substring
method can easily handle all formats of the VB methods. You will have to
convert
from using 1 based indexing to 0 based indexing, since the VB functions use 1 to
denote the first character and Substring uses 0.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"A.M" <IH*******@sapm123.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
Hi,

Using C#, what is the equivalent of functions Left, Right and Mid that we
had in vb6?

Thanks,
Alan

Nov 16 '05 #3
as well as the answers the other guys have provided, you can also import the
visualbasic lib and actually use left, right and mid in c'

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"A.M" <IH*******@sapm123.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
Hi,

Using C#, what is the equivalent of functions Left, Right and Mid that we
had in vb6?

Thanks,
Alan

Nov 16 '05 #4
A.M
Thaks John, That is actually a good idea!

"John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
news:uA*************@tk2msftngp13.phx.gbl...
as well as the answers the other guys have provided, you can also import the visualbasic lib and actually use left, right and mid in c'

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"A.M" <IH*******@sapm123.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
Hi,

Using C#, what is the equivalent of functions Left, Right and Mid that we had in vb6?

Thanks,
Alan


Nov 16 '05 #5
A.M <IH*******@sapm123.com> wrote:
Thaks John, That is actually a good idea!


No, it's not. Substring is a perfectly good alternative, and one which
stays within the idiom of C# and .NET, rather than making your code
look like a mixture of C# and old VB.

It will work, but it will be harder for other C# programmers (without
VB experience) to understand. It will require the Microsoft.VisualBasic
assembly to be loaded for no particularly good reason. It will use a
method which has been significantly less thoroughly tested than
Substring (because virtually all .NET programmers use Substring whereas
only a few will be using the ported VB methods).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
"A.M" <IH*******@sapm123.com> wrote in news:uMMhrMSPEHA.1392
@TK2MSFTNGP09.phx.gbl:
Using C#, what is the equivalent of functions Left, Right and Mid that we
had in vb6?


Remember that in .NET strings are objects. So dont look for global functions,
but look at the methods of the string object itself.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
Nov 16 '05 #7
I couldn't agree more. Just because something can be done
is not a logical reason for doing so.
--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
A.M <IH*******@sapm123.com> wrote:
Thaks John, That is actually a good idea!
No, it's not. Substring is a perfectly good alternative, and one which
stays within the idiom of C# and .NET, rather than making your code
look like a mixture of C# and old VB.

It will work, but it will be harder for other C# programmers (without
VB experience) to understand. It will require the

Microsoft.VisualBasic assembly to be loaded for no particularly good reason. It will use a
method which has been significantly less thoroughly tested than
Substring (because virtually all .NET programmers use Substring whereas only a few will be using the ported VB methods).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #8
A.M
Thank you for comment.

Unfotunately, I have to be 100% agree with you about about using
Microsoft.VisualBasic assmebly; however I have to subclass my own simple
string class to abstract Left and Mid and Right. It is not the name of
function. It is more convenient to send a simple parameter which is really
needed for that operation if we use it too often.

I was excited because I didn't think about using Microsoft.VisualBasic
assmebly in C# !

Thank you again,
Alan

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
A.M <IH*******@sapm123.com> wrote:
Thaks John, That is actually a good idea!


No, it's not. Substring is a perfectly good alternative, and one which
stays within the idiom of C# and .NET, rather than making your code
look like a mixture of C# and old VB.

It will work, but it will be harder for other C# programmers (without
VB experience) to understand. It will require the Microsoft.VisualBasic
assembly to be loaded for no particularly good reason. It will use a
method which has been significantly less thoroughly tested than
Substring (because virtually all .NET programmers use Substring whereas
only a few will be using the ported VB methods).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9

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

Similar topics

3
by: mitsura | last post by:
Hi, I have included a small listing. The test program opens a panel and show a bitmap. What I want is to when the mouse is over the bitmap panel, I want to trap the left mouse click. The...
11
by: Bruce A. Julseth | last post by:
I have: If (Microsoft.VisualBasic.Left(TextBox1.Text, 1) = "$") Then TextBox1.Text = Microsoft.VisualBasic.Right(TextBox1.Text, TextBox1.Text.Length - 1) End If Adding: Imports...
6
by: James Brown [MVP] | last post by:
Hi, I am having trouble understanding how the 'const' modifier affects the 'left-right' rule when deciphering c-declarations: const int *x; // x is a pointer to a 'const int' int const *x; ...
8
by: Chaitanya | last post by:
Hello, In my Application i want to know when user clicks both the "Left" and "Right" buttons of the Mouse. I am getting a number like this "3145728". But the MouseButtons Enum contains only Left,...
5
by: | last post by:
What are the equivalant to left, right, etc. in C#. How can I extract strings from a string without them? For instance, I have a string like so: ...
14
TheServant
by: TheServant | last post by:
Hi guys, I have done this before, but I can't figure out why it won't work. If any of you can see my problem, please let me know. Here are the relavent pieces of code. <!-- Main Content --> <div...
9
by: shapper | last post by:
Hello, I am used to SQL but I am starting to use LINQ. How can I create Left, Right and Inner joins in LINQ? How to distinguish the different joins? Here is a great SQL example:...
16
by: ImpactMan | last post by:
Need help to create an windows mobile application with a few buttons that when they are pressed/clicked they assign keys, like up, down, left, right. It is just like to create a "virtual d-pad",...
0
by: garfieldsevilla | last post by:
I have a report in Access 2003 which consists of a header with two fields and a subform pasted into the centre. When I open this form, it always displays in Print Preview and I cannot find an...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.