substring and return the value after a specific character

72,272

Solution 1

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)

Solution 2

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);
Share:
72,272
Fire Hand
Author by

Fire Hand

Updated on July 09, 2022

Comments

  • Fire Hand
    Fire Hand almost 2 years

    "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?

  • ourmandave
    ourmandave over 2 years
    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 ":".