?
Solved

Remove Bracket and Its Value.

Posted on 2009-04-07
8
Medium Priority
?
182 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 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