Solved

Remove Bracket and Its Value.

Posted on 2009-04-07
8
175 Views
Last Modified: 2012-05-06
Hi,

I want to Remove Bracket and Its Value.

I have 3 functions to do it.

Public Shared Function Remove_Bracket_And_Its_Value(ByVal strData As String) As String

        Dim strValue As String = ERV_Global.Get_Value_Inside_Bracket(strData)

        strData = Replace(strData, strValue, "")

        strData = Remove_Bracket(strData)

        Return strData

    End Function

Could we make it simple the above function?

Thank you.

Public Shared Function Get_Value_Inside_Bracket(ByVal strData As String) As String
 
        If strData.Trim = "" Then Return ""
 
        Dim sep() As Char = New Char() {"(", ")"}
        Dim result() As String = strData.Split(sep)
 
        Return result(1)
 
    End Function
 
 
 Public Shared Function Remove_Bracket(ByVal strData As String) As String
 
        strData = Replace(strData, ")", "")
        strData = Replace(strData, "(", "")
 
        Return strData
 
    End Function

Open in new window

0
Comment
Question by:emi_sastra
  • 4
  • 4
8 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24090759
Maybe this way
    Public Shared Function Remove_Bracket(ByVal strData As String) As String
        Return strData.Replace(")", "").Replace("(", "")
    End Function

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24090805
Hi jpaulino,

My main target is below function:

Public Shared Function Get_Value_Inside_Bracket(ByVal strData As String) As String
 
        If strData.Trim = "" Then Return ""
 
        Dim sep() As Char = New Char() {"(", ")"}
        Dim result() As String = strData.Split(sep)
 
        Return result(1)
 
    End Function


ie.  CustCode (Char(6)) ----> CustCode

Thank you.


0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24090814
Sorry,

I mean below function:

Public Shared Function Remove_Bracket_And_Its_Value(ByVal strData As String) As String

        Dim strValue As String = ERV_Global.Get_Value_Inside_Bracket(strData)

        strData = Replace(strData, strValue, "")

        strData = Remove_Bracket(strData)

        Return strData

    End Function

ie.  CustCode (Char(6)) ----> CustCode

Thank you.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 48

Expert Comment

by:jpaulino
ID: 24090905
You have this "CustCode (Char(6))" and you want to return what ?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24090929
You have this "CustCode (Char(6))" and you want to return what ?
To "CustCode"

Or "(aaaa) CustCode (Char(6))"  To CustCode.
Remove anything inside bracket and its bracket.

Thank you.
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24091055
Try this way
    Public Shared Function Remove_Bracket_And_Its_Value(ByVal strData As String) As String
        Dim posStart As Integer = strData.IndexOf("("c)
        Dim posEnd As Integer = strData.IndexOf(")"c)
 
        While (posStart <> -1 AndAlso posEnd <> -1)
            strData = strData.Remove(posStart, posEnd - posStart + 1)
            posStart = strData.IndexOf("("c, posStart)
            If posStart <> -1 Then
                posEnd = strData.IndexOf(")"c, posStart)
            Else
                posEnd = strData.IndexOf(")"c)
            End If
 
        End While
 
        Return strData.Replace("(", "").Replace(")", "")
    End Function

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24091128
It works.

Thank you very much for your help.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24091194
Glad I could help!
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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