?
Solved

Remove Bracket and Its Value.

Posted on 2009-04-07
8
Medium Priority
?
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 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