Solved

Remove Bracket and Its Value.

Posted on 2009-04-07
8
173 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
 
LVL 48

Expert Comment

by:jpaulino
ID: 24090905
You have this "CustCode (Char(6))" and you want to return what ?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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