none
How to remove string back and front RRS feed

  • Question

  • Hi All,

    I have striing in List like this;

    Max :15(0)Max :15(0)
    Max :11(1)Max :11(1)
    Max :12(2)Max :12(2)
    Max :6(3)Max :6(3)
    Max :7(4)Max :7(4)
    Max :16(5)Max :16(5)
    Max :1(6)Max :1(6)
    Max :16(7)Max :16(7)
    Max :17(8)Max :17(8)
    Max :15(9)Max :15(9)

    in TextBox1 .I want to show in TextBox2 as bellow;

    00
    11
    22
    33
    44
    55
    66
    77
    88
    99

    I want leave then umnber in bracket only.

    Thank.

    Public Class Form1
        Private A_ As New List(Of String)
        Private B_ As New List(Of String)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            For j As Integer = 0 To 9
                Dim value As Integer = CInt(Int((20 * Rnd()) + 1))
                A_.Add("Max :" & value & "(" & j & ")")
    
            Next
    
            For I As Integer = 0 To A_.Count - 1
                TextBox1.AppendText(A_(I) & A_(I) & vbCrLf)
                B_.Add(A_(I) & A_(I))
            Next
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            For I As Integer = 0 To B_.Count - 1
                Dim List As String = B_(I)
                List = List.Replace("Max :", "")
                List = List.Remove(0, List.IndexOf("(") + 1)
                List = List.Remove(List.LastIndexOf(")"))
    
                'List = List.Remove(")", "(","")
                'Dim subst As String = List.Substring("(", ")")
    
                Me.TextBox2.AppendText(List & vbCrLf)
    
    
    
            Next
    
    
        End Sub
    End Class


    • Edited by mipakteh Wednesday, January 1, 2020 5:01 AM repair
    Wednesday, January 1, 2020 4:57 AM

Answers

  • Hi,

    How about this code?
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        For I As Integer = 0 To B_.Count - 1
            Dim List As String = B_(I)
            Dim first, second As String
            first = Mid(List, List.IndexOf("(") + 2, 1)
            second = Mid(List, List.Length - 1, 1)
            Me.TextBox2.AppendText(first & second & vbCrLf)
        Next
    End Sub
        

    Regards,

    Ashidacchi -- http://hokusosha.com


    • Edited by Ashidacchi Wednesday, January 1, 2020 6:40 AM
    • Marked as answer by mipakteh Wednesday, January 1, 2020 7:39 AM
    Wednesday, January 1, 2020 6:36 AM

  • I want leave then umnber in bracket only.


    Public Class Form1
        Private A_ As New List(Of String)
        Private B_ As New List(Of String)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            For j As Integer = 0 To 9
                Dim value As Integer = CInt(Int((20 * Rnd()) + 1))
                A_.Add("Max :" & value & "(" & j & ")")
    
            Next
    
            For I As Integer = 0 To A_.Count - 1
                TextBox1.AppendText(A_(I) & A_(I) & vbCrLf)
                B_.Add(A_(I) & A_(I))
            Next
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            For I As Integer = 0 To B_.Count - 1
                Dim List As String = B_(I)
                List = List.Replace("Max :", "")
                List = List.Remove(0, List.IndexOf("(") + 1)
                List = List.Remove(List.LastIndexOf(")"))
    
                'List = List.Remove(")", "(","")
                'Dim subst As String = List.Substring("(", ")")
    
                Me.TextBox2.AppendText(List & vbCrLf)
    
    
    
            Next
    
    
        End Sub
    End Class

    Working with what you've already got:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        For I As Integer = 0 To B_.Count - 1
            Dim List As String = B_(I)
            List = List.Replace("Max :", "")
            List = List.Remove(0, List.IndexOf("(") + 1)
            List = List.Remove(List.LastIndexOf(")"))
    
            'List = List.Remove(")", "(","")
            'Dim subst As String = List.Substring("(", ")")
    
            List = List.Remove(List.IndexOf(")"), List.LastIndexOf("("))
    
            Me.TextBox2.AppendText(List & vbCrLf)
    
        Next
    End Sub
    

    - Wayne

    • Marked as answer by mipakteh Wednesday, January 1, 2020 7:38 AM
    Wednesday, January 1, 2020 6:44 AM

All replies

  • Hi,

    How about this code?
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        For I As Integer = 0 To B_.Count - 1
            Dim List As String = B_(I)
            Dim first, second As String
            first = Mid(List, List.IndexOf("(") + 2, 1)
            second = Mid(List, List.Length - 1, 1)
            Me.TextBox2.AppendText(first & second & vbCrLf)
        Next
    End Sub
        

    Regards,

    Ashidacchi -- http://hokusosha.com


    • Edited by Ashidacchi Wednesday, January 1, 2020 6:40 AM
    • Marked as answer by mipakteh Wednesday, January 1, 2020 7:39 AM
    Wednesday, January 1, 2020 6:36 AM

  • I want leave then umnber in bracket only.


    Public Class Form1
        Private A_ As New List(Of String)
        Private B_ As New List(Of String)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            For j As Integer = 0 To 9
                Dim value As Integer = CInt(Int((20 * Rnd()) + 1))
                A_.Add("Max :" & value & "(" & j & ")")
    
            Next
    
            For I As Integer = 0 To A_.Count - 1
                TextBox1.AppendText(A_(I) & A_(I) & vbCrLf)
                B_.Add(A_(I) & A_(I))
            Next
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            For I As Integer = 0 To B_.Count - 1
                Dim List As String = B_(I)
                List = List.Replace("Max :", "")
                List = List.Remove(0, List.IndexOf("(") + 1)
                List = List.Remove(List.LastIndexOf(")"))
    
                'List = List.Remove(")", "(","")
                'Dim subst As String = List.Substring("(", ")")
    
                Me.TextBox2.AppendText(List & vbCrLf)
    
    
    
            Next
    
    
        End Sub
    End Class

    Working with what you've already got:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        For I As Integer = 0 To B_.Count - 1
            Dim List As String = B_(I)
            List = List.Replace("Max :", "")
            List = List.Remove(0, List.IndexOf("(") + 1)
            List = List.Remove(List.LastIndexOf(")"))
    
            'List = List.Remove(")", "(","")
            'Dim subst As String = List.Substring("(", ")")
    
            List = List.Remove(List.IndexOf(")"), List.LastIndexOf("("))
    
            Me.TextBox2.AppendText(List & vbCrLf)
    
        Next
    End Sub
    

    - Wayne

    • Marked as answer by mipakteh Wednesday, January 1, 2020 7:38 AM
    Wednesday, January 1, 2020 6:44 AM
  • Thank you very much WayneKing.

    Wednesday, January 1, 2020 7:38 AM
  • Thank Ashidacchi for support
    Wednesday, January 1, 2020 7:39 AM
  • Hi,

    Unlike the answer above, you can use regular expressions to achieve the result you want, so you can quickly extract the content in brackets. Just change your code as follows:

    Add the following namespaces:

    Imports System.Text.RegularExpressions

    Change your Button1 code:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            For I As Integer = 0 To B_.Count - 1
                Dim List As String = B_(I)
    
                Dim reg As Regex = New Regex("(?is)(?<=\()[^\)]+(?=\))")
                Dim mc As MatchCollection = reg.Matches(List)
    
                For Each m As Match In mc
                    Me.TextBox2.AppendText(m.Value)
                Next
                Me.TextBox2.AppendText(vbCrLf)
    
            Next
        End Sub

    Effects:

    If you want to learn more about regular expressions, you can browse the documentation links provided below:

    https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=netframework-4.8

    Hope it be helpful.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, January 1, 2020 8:44 AM
    Moderator
  • Thank you very much.Julie
    Wednesday, January 8, 2020 4:43 AM