12

"Testing.BSMain, Text: Start Page"

I would like to substring the value above and returning me only the value after the ": " in vb.net. How can i do that?

Fire Hand
  • 25,366
  • 22
  • 53
  • 76
  • 1
    possible duplicate of [String substring function](http://stackoverflow.com/questions/1082650/string-substring-function) – Ken White Jun 21 '12 at 02:19

3 Answers3

27

Assumes no error checking:

Dim phrase As String = "Testing.BSMain, Text: Start Page".Split(":")(1)

which simply splits the phrase by the colon and returns the second part.

To use SubString, try this:

Dim test As String = "Testing.BSMain, Text: Start Page"
Dim phrase As String = test.Substring(test.IndexOf(":"c) + 1)
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • Don't use Split if your original string has more than one ":" or you'll only get back what's between the first to the second ":". – ourmandave Jan 06 '22 at 16:54
9

you can use the split method to return the value after the colon :

   Dim word as String  = "Testing.BSMain, Text: Start Page"
   Dim wordArr as String()  = word.Split(":")
   Dim result as String = wordArr(1);
Nudier Mena
  • 3,254
  • 2
  • 22
  • 22
0

If proposed solutions don't work for you I did it this way:

result= Split("Testing.BSMain, Text: Start Page", ":")(1)
Duhu
  • 28
  • 4