Serach throug string

Posted on 2007-08-08
Last Modified: 2013-11-05
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?
Question by:jsctechy
    LVL 38

    Expert Comment

    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)

        End Sub
    End Class
    LVL 33

    Expert Comment

    You can try this

    Imports System.Text.RegularExpressions

            Dim str As String = "D01D02D03D04D05D06T01T02T03T04"
            Dim str2 = New Regex("[^T]").Replace(str, "")
    LVL 96

    Accepted Solution

    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)
    Next m

    LVL 33

    Expert Comment

    I could have misunderstood the question.
    LVL 62

    Expert Comment

    by:Fernando Soto
    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
            End If

    LVL 1

    Author Comment


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now