Text.Substring

  • Thread starter Thread starter cmdolcet69
  • Start date Start date
C

cmdolcet69

Dim mystring As String
mystring = txtInputValues.Text
mystring.Substring(mystring.Length - 3)


I want my mystring to display the last 3 from the txtinputValue.text
string. What im I doing wrong?
 
Dim mystring As String
mystring = txtInputValues.Text
mystring.Substring(mystring.Length - 3)

I want my mystring to display the last 3 from the txtinputValue.text
string. What im I doing wrong?

You are not assigning it:

mystring = mystring.Substring(mystring.Length - 3)

Thanks,

Seth Rowe [MVP]
 
cmdolcet69 said:
Dim mystring As String
mystring = txtInputValues.Text
mystring.Substring(mystring.Length - 3)


I want my mystring to display the last 3 from the txtinputValue.text
string. What im I doing wrong?

Note that SubString is a function. You are ignoring it's return value.


Armin
 
In addition to what the others said, make sure you add a check for the length
of mystring. You will get a runtime error if the length is less than three.
 
cmdolcet69 said:
Dim mystring As String
mystring = txtInputValues.Text
mystring.Substring(mystring.Length - 3)


I want my mystring to display the last 3 from the txtinputValue.text
string. What im I doing wrong?

Imports VB=Microsoft.VisualBasic

Dim mystring as String=VB.Right(txtInputValues.Text, 3)

Andrew
 
Andrew,

There is no import needed for Microsoft.VisualBasic,

It is standard in the project properties

Cor
 
Cor said:
There is no import needed for Microsoft.VisualBasic,

It is standard in the project properties

I tend to do that because it's easier to qualify it as VB.Right rather than
Microsoft.VisualBasic.Right. Otherwise the VB compiler in VS2003 can see it
as a window/form property rather than the Right string function from VB. (Or
maybe it only does that with Left, but for symmetry I do it with Right too.)

Andrew
 
Back
Top