tags:

views:

74

answers:

5

Hello, I how do I find the last but one character in a string in VB.net.

for e.g. I have a string Dim strTicket as string="56789-091F0" I want the value "F"

Thanks for your help in advance.

A: 

have a look at .Substring() method: http://msdn.microsoft.com/en-us/library/system.string.substring.aspx

rochal
+2  A: 
Dim strTicket as string="56789-091F0"
Console.WriteLine(strTicket.Substring(strTicket.Length-2,1))

Check that your string is long enough before doing this tho!!

CResults
A: 

use the substring

      "56789-091F0".Substring(Len("56789-091F0")-2,1)
Fredou
+5  A: 

Just select it as you would the next to last element of an array. I don't see the need for all the extra stuff.

Dim newChar As Char = strTicket(strTicket.Length - 2)
JTA
A: 
Dim s As String = "56789-091F0"
Dim c as Char = s(s.length - 2)
Fabian