How to substring a set of text received in vb.net?

Eekhay 101 Reputation points
2022-03-09T17:53:29.19+00:00

Hi All,

A set of text received as of format below.

AB123456789A123 123-12345-12 ABC: 12

The text length for the first subset text and second subset text varies but each subset text is separated by space.
How to grep the second subset text (123-12345-12) using VB.net?

Thank you.

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. LesHay 7,141 Reputation points
    2022-03-09T17:57:49.123+00:00

    Hi
    One example:

     Dim mystring As String = "123-12345-12"
     Dim sp() As String = Split(mystring, "-"c)
    
     ' the array now holds the substrings
     ' sp(0) = 123  (string value)
     ' sp(1) = 12345
     ' sp(2) = 12
    

    'OR, using first string

        Dim incoming As String = "AB123456789A123 123-12345-12 ABC: 12"
        Dim sp() As String = Split(incoming.Split(" "c)(1), "-"c)
    
        ' the array now holds the substrings
        ' sp(0) = 123  (string value)
        ' sp(1) = 12345
        ' sp(2) = 12
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Eekhay 101 Reputation points
    2022-03-09T18:42:04.117+00:00

    Hi @LesHay and All,

    Sorry for the confusion.

    A string/text (AB123456789A123 123-12345-12 ABC: 12) received has three subset of string/text.
    The first subset of string/text is AB123456789A123
    The second subset of string/text is 123-12345-12
    The third subset of string/text is ABC: 12
    Each subset of string/text is separated by space.
    The length of the first subset of string/text (AB123456789A123) and the second subset of string/text (123-12345-12) is vary

    How to grep the second subset of string/text (123-12345-12) and populate it in the text box?

    Thank you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.