left, mid and right in vb.net

  • Thread starter Thread starter ReidarT
  • Start date Start date
Hello,

If you declare a string and you can simply use the functions as follows:-

Dim s As String
s = Left(s, length)
s = Mid(s, start, length)
s = Right(s, length)

Substring function is provided instead of using of the above.

E.g.

Dim s As String
s = s.SubString(start)
s = s.Substring(start, length)

Where start = the index of the character to start from,
and length = the number of characters to take.

Hope this helps,
Simon Jefferies
mailto:simon[nospam]@cooltoolsonline.co.uk
-- remove [nospam] to email me --
 
* "ReidarT said:
How do I use left, mid and right in vb.net?

I qualify these methods with the module that contains them:

'Strings.Left', 'Strings.Right', 'Strings.Mid'.
 
if I use the mid-function, it works, but if I use left-function it does not
work
Here is the code:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim s As String
s = TextBox1.Text
s = Mid(s, 3, 4)
Label1.Text = s
End Sub
reidarT
 
Hello,

In what way does it not work?

You seem to be retrieving the middle part of a string from a textbox entry,
where as using the Left function is to return the leftmost characters only.
You may get an error if you try to retrieve letters from a string when there
aren't enough in it?

Regards
Simon Jefferies
mailto:simon[nospam]@cooltoolsonline.co.uk
-- remove [nospam] to email me --
 
I enjoy watching these threads, the irritation is muted but obvious
nevertheless ;-)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

Simon Jefferies said:
Hello,

In what way does it not work?

You seem to be retrieving the middle part of a string from a textbox entry,
where as using the Left function is to return the leftmost characters only.
You may get an error if you try to retrieve letters from a string when there
aren't enough in it?

Regards
Simon Jefferies
mailto:simon[nospam]@cooltoolsonline.co.uk
-- remove [nospam] to email me --


ReidarT said:
if I use the mid-function, it works, but if I use left-function it does
not
work
Here is the code:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim s As String
s = TextBox1.Text
s = Mid(s, 3, 4)
Label1.Text = s
End Sub
reidarT
 
It may be that Left is a property of forms and controls and if this is used
in a Form class, it probably won't work. Try importing Microsoft Visual
Basic like

Imports vb = Microsoft.VisualBasic
You can then use VB.Left(xxx,3) or whatever.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top