473,526 Members | 2,906 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 38619
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
3593
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 purpose is to get the position of the mouse pointer on the bitmap. However, for some reason, the left (I also tried right) mouse clicks are not...
11
5091
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 Microsoft.VisualBasic
6
2210
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; // ?? these are the same, right? in this case the basetype is 'const int' ? int * const x = 0; // x is a const-pointer to int
8
4602
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, Right, Middle, None, XButton1 and XButton2. I am using .NET 1.1 version. How can i convert "3145728" to MouseButtons Enum? why Mouse Left+Right...
5
3028
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: "c:\thedir\subfolder\maybeanother\__TFMF_lrniez55ufziugv2nnznzeyt_b9c9c1d5-230a-43e1-b38a-7a44_0___Selected.eps" I need to return just the directory name "c:\thedir\subfolder\maybeanother\"...
14
2664
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 class="main_content"> <!-- Content --> <div class="content"> <p>main content</p> </div> <!-- End of Content -->
9
11909
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: http://www.codinghorror.com/blog/archives/000976.html
16
4079
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", or "software emulated d-pad". I'm newbie in programming, and I'm using Visual Studio 2008. Some one can help me with that? Tanks. My effort...
0
1412
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 setting for default view. I would prefer it showed in Layout Preview. Can anyone help with this setting? Also in Print Preview, the left, right and top...
0
7329
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7253
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7653
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7604
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4820
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3316
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
890
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.