0
text1/text2/text3

In this text, I am trying to get text3 only. Is there anyway that I can do this in VB.Net?

By the way, "text1/text2/" is fixed. So they are not changing.

Eren
  • 183
  • 2
  • 13

4 Answers4

1

use substring since you know the index position of the character.The code below is usefull for you if the "text1 and text2" varies dynamically

    Dim line as string="text1/text2/text3"
    Dim _split = line.Split("/")(2)
    MessageBox.Show(_split)
Venkatvasan
  • 491
  • 3
  • 13
  • It would probably be best to verify that there are at least three elements in the array returned by the `Split` method before attempting to use the third element – Blackwood Aug 13 '15 at 13:43
0

I fixed the problem with removing first 22 character.

Example

X = text1/text2/text3
Y = X.text.Remove(0, 12)
Result = text3
Matt
  • 74,352
  • 26
  • 153
  • 180
Eren
  • 183
  • 2
  • 13
0

Use String.Substring(Int32, Int32) method. String.Substring(12, totalLength - 12) will return the "text3" in your case. Here totalLength is the total length of the text "text1/text2/text3".

Check this link from msdn website:

I-A-N
  • 159
  • 3
  • 3
-1

you can use SubString like

string sub = "text1/text2/text3".Substring(12, 5);

VB

Dim subString As String = "text1/text2/text3".Substring(12, 5)

or you can refer to this Find text in string with C#

Community
  • 1
  • 1
Ali Umair
  • 1,386
  • 1
  • 21
  • 42
  • the OP specified VB. `sub` is a reserved word in VB. Also, the result of your code would be the first 12 characters, not what the OP asked for. – Sam Axe Aug 13 '15 at 09:52