• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

Serach throug string

hi there,
i have a long string that  needs to be break down depending on its value. for instance the string looks like this: D01D02D03D04D05D06T01T02T03T04
so what i need to do is to get only the T's and dont pick the other stuff. How can i do this?
Thanks
0
jsctechy
Asked:
jsctechy
1 Solution
 
PaulHewsCommented:
Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Pattern As String = "T([\d]+)"
        Dim TestString As String = "D01D02D03D04D05D06T01T02T03T04"
        Dim Regex As New Regex(Pattern)
        For Each m As Match In Regex.Matches(TestString)
            Debug.WriteLine(m.Groups(1).Value)

        Next
    End Sub
End Class
0
 
hongjunCommented:
You can try this

Imports System.Text.RegularExpressions
'''
'''

        Dim str As String = "D01D02D03D04D05D06T01T02T03T04"
        Dim str2 = New Regex("[^T]").Replace(str, "")
        Console.WriteLine(str2)
0
 
Bob LearnedCommented:
If you just need T01, T02, T03, ..., then you can use Regex

Imports System.Text.RegularExpressions

...

Dim input As String = "D01D02D03D04D05D06T01T02T03T04"
Dim pattern As String = "T\d{2}"
For Each m As Match In Regex.Matches(input, pattern)
   Console.WriteLine(m.Value)
Next m

Bob
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hongjunCommented:
I could have misunderstood the question.
0
 
Fernando SotoCommented:
Hi jsctechy;

Here is a solution using Regular Expressions.

Imports System.Text.RegularExpressions

        Dim inputStr As String = " D01D02D03D04D05D06T01T02T03T04"
        Dim mc As MatchCollection = Regex.Matches(inputStr, "(T\d+)")

        If mc.Count > 0 Then
            For Each m As Match In mc
                Console.WriteLine(m.Groups(1).Value)
            Next
        End If

Fernando
0
 
jsctechyAuthor Commented:
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now