Remove what is second parentheses of a string vb.net











up vote
0
down vote

favorite












i have a string like this



blabla (lo-g) (kk-jj)


i want to make it like this



blabla (lo-g)


but when it's already like this in vb.net



blabla (lo-g) with one parenteses


just let it as and is



thanks










share|improve this question






















  • What would you want to happen with strings like blabla (lo-g) with (kk-jj) trailing and blabla (lo-g) (kk-jj) trailing
    – Steven Doggart
    Nov 9 at 16:27















up vote
0
down vote

favorite












i have a string like this



blabla (lo-g) (kk-jj)


i want to make it like this



blabla (lo-g)


but when it's already like this in vb.net



blabla (lo-g) with one parenteses


just let it as and is



thanks










share|improve this question






















  • What would you want to happen with strings like blabla (lo-g) with (kk-jj) trailing and blabla (lo-g) (kk-jj) trailing
    – Steven Doggart
    Nov 9 at 16:27













up vote
0
down vote

favorite









up vote
0
down vote

favorite











i have a string like this



blabla (lo-g) (kk-jj)


i want to make it like this



blabla (lo-g)


but when it's already like this in vb.net



blabla (lo-g) with one parenteses


just let it as and is



thanks










share|improve this question













i have a string like this



blabla (lo-g) (kk-jj)


i want to make it like this



blabla (lo-g)


but when it's already like this in vb.net



blabla (lo-g) with one parenteses


just let it as and is



thanks







asp.net vb.net trim






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 16:17









Otmane Hatiji

135




135












  • What would you want to happen with strings like blabla (lo-g) with (kk-jj) trailing and blabla (lo-g) (kk-jj) trailing
    – Steven Doggart
    Nov 9 at 16:27


















  • What would you want to happen with strings like blabla (lo-g) with (kk-jj) trailing and blabla (lo-g) (kk-jj) trailing
    – Steven Doggart
    Nov 9 at 16:27
















What would you want to happen with strings like blabla (lo-g) with (kk-jj) trailing and blabla (lo-g) (kk-jj) trailing
– Steven Doggart
Nov 9 at 16:27




What would you want to happen with strings like blabla (lo-g) with (kk-jj) trailing and blabla (lo-g) (kk-jj) trailing
– Steven Doggart
Nov 9 at 16:27












3 Answers
3






active

oldest

votes

















up vote
1
down vote













i want to thanks steven for his answer but for those who can't handle regex (like me)
here's a simple stupid method



Dim res As String = String.Empty

Dim check As Boolean = False

For Each letter In teamname
If letter = "(" Then
If check = True Then
Exit For
End If
check = True
End If
res &= letter

Next

Return res


good luck






share|improve this answer





















  • This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
    – Mary
    Nov 9 at 17:40


















up vote
0
down vote













Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:



Dim input As String = "blabla (lo-g) (kk-jj)"
Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
Dim output As String = Regex.Replace(input, pattern, "")


However, that will not remove the second set of parenthesis for inputs like these:



blabla (lo-g) blabla (kk-jj) blabla
blabla (lo-g) (kk-jj) blabla


To handle variations like those, you could use a pattern like this:



Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
Dim output As String = Regex.Replace(input, pattern, "")





share|improve this answer























  • thank you these regex work very well for me, but i didn't understand them that's why i create my own method
    – Otmane Hatiji
    Nov 9 at 17:22


















up vote
0
down vote













Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).



Essentially splitting your string into this:
"blabla (lo-g) (kk-jj)"



Array(0) = "blabla "
Array(1) = "lo-g) "



So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character



    Dim SplitText = text.Split("(")

If SplitText.Length > 1 Then
Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
'This may be easier for you to read, though:
'Return text.Split("(")(0) & "(" & text.Split("(")(1)
End If

Return text





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229469%2fremove-what-is-second-parentheses-of-a-string-vb-net%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    i want to thanks steven for his answer but for those who can't handle regex (like me)
    here's a simple stupid method



    Dim res As String = String.Empty

    Dim check As Boolean = False

    For Each letter In teamname
    If letter = "(" Then
    If check = True Then
    Exit For
    End If
    check = True
    End If
    res &= letter

    Next

    Return res


    good luck






    share|improve this answer





















    • This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
      – Mary
      Nov 9 at 17:40















    up vote
    1
    down vote













    i want to thanks steven for his answer but for those who can't handle regex (like me)
    here's a simple stupid method



    Dim res As String = String.Empty

    Dim check As Boolean = False

    For Each letter In teamname
    If letter = "(" Then
    If check = True Then
    Exit For
    End If
    check = True
    End If
    res &= letter

    Next

    Return res


    good luck






    share|improve this answer





















    • This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
      – Mary
      Nov 9 at 17:40













    up vote
    1
    down vote










    up vote
    1
    down vote









    i want to thanks steven for his answer but for those who can't handle regex (like me)
    here's a simple stupid method



    Dim res As String = String.Empty

    Dim check As Boolean = False

    For Each letter In teamname
    If letter = "(" Then
    If check = True Then
    Exit For
    End If
    check = True
    End If
    res &= letter

    Next

    Return res


    good luck






    share|improve this answer












    i want to thanks steven for his answer but for those who can't handle regex (like me)
    here's a simple stupid method



    Dim res As String = String.Empty

    Dim check As Boolean = False

    For Each letter In teamname
    If letter = "(" Then
    If check = True Then
    Exit For
    End If
    check = True
    End If
    res &= letter

    Next

    Return res


    good luck







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 9 at 17:20









    Otmane Hatiji

    135




    135












    • This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
      – Mary
      Nov 9 at 17:40


















    • This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
      – Mary
      Nov 9 at 17:40
















    This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
    – Mary
    Nov 9 at 17:40




    This works great for a very specific case and if you are sure you strings will conform to this case it is fine.
    – Mary
    Nov 9 at 17:40












    up vote
    0
    down vote













    Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:



    Dim input As String = "blabla (lo-g) (kk-jj)"
    Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
    Dim output As String = Regex.Replace(input, pattern, "")


    However, that will not remove the second set of parenthesis for inputs like these:



    blabla (lo-g) blabla (kk-jj) blabla
    blabla (lo-g) (kk-jj) blabla


    To handle variations like those, you could use a pattern like this:



    Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
    Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
    Dim output As String = Regex.Replace(input, pattern, "")





    share|improve this answer























    • thank you these regex work very well for me, but i didn't understand them that's why i create my own method
      – Otmane Hatiji
      Nov 9 at 17:22















    up vote
    0
    down vote













    Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:



    Dim input As String = "blabla (lo-g) (kk-jj)"
    Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
    Dim output As String = Regex.Replace(input, pattern, "")


    However, that will not remove the second set of parenthesis for inputs like these:



    blabla (lo-g) blabla (kk-jj) blabla
    blabla (lo-g) (kk-jj) blabla


    To handle variations like those, you could use a pattern like this:



    Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
    Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
    Dim output As String = Regex.Replace(input, pattern, "")





    share|improve this answer























    • thank you these regex work very well for me, but i didn't understand them that's why i create my own method
      – Otmane Hatiji
      Nov 9 at 17:22













    up vote
    0
    down vote










    up vote
    0
    down vote









    Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:



    Dim input As String = "blabla (lo-g) (kk-jj)"
    Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
    Dim output As String = Regex.Replace(input, pattern, "")


    However, that will not remove the second set of parenthesis for inputs like these:



    blabla (lo-g) blabla (kk-jj) blabla
    blabla (lo-g) (kk-jj) blabla


    To handle variations like those, you could use a pattern like this:



    Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
    Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
    Dim output As String = Regex.Replace(input, pattern, "")





    share|improve this answer














    Regex is a powerful, flexible, and configurable tool for doing things like this. It's not entirely clear from your question exactly what rules need to be followed in other variations for the input, but here's an example which works for the inputs you specified:



    Dim input As String = "blabla (lo-g) (kk-jj)"
    Dim pattern As String = "(?<=^[^(]*([^)]*)s*)([^)]*)(?=s*$)"
    Dim output As String = Regex.Replace(input, pattern, "")


    However, that will not remove the second set of parenthesis for inputs like these:



    blabla (lo-g) blabla (kk-jj) blabla
    blabla (lo-g) (kk-jj) blabla


    To handle variations like those, you could use a pattern like this:



    Dim input As String = "blabla (lo-g) with (kk-jj) trailing"
    Dim pattern As String = "(?<=^[^(]*([^)]*)[^(]*)([^)]*)(?=[^(]*$)"
    Dim output As String = Regex.Replace(input, pattern, "")






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 9 at 16:53

























    answered Nov 9 at 16:46









    Steven Doggart

    37.4k44084




    37.4k44084












    • thank you these regex work very well for me, but i didn't understand them that's why i create my own method
      – Otmane Hatiji
      Nov 9 at 17:22


















    • thank you these regex work very well for me, but i didn't understand them that's why i create my own method
      – Otmane Hatiji
      Nov 9 at 17:22
















    thank you these regex work very well for me, but i didn't understand them that's why i create my own method
    – Otmane Hatiji
    Nov 9 at 17:22




    thank you these regex work very well for me, but i didn't understand them that's why i create my own method
    – Otmane Hatiji
    Nov 9 at 17:22










    up vote
    0
    down vote













    Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).



    Essentially splitting your string into this:
    "blabla (lo-g) (kk-jj)"



    Array(0) = "blabla "
    Array(1) = "lo-g) "



    So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character



        Dim SplitText = text.Split("(")

    If SplitText.Length > 1 Then
    Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
    'This may be easier for you to read, though:
    'Return text.Split("(")(0) & "(" & text.Split("(")(1)
    End If

    Return text





    share|improve this answer

























      up vote
      0
      down vote













      Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).



      Essentially splitting your string into this:
      "blabla (lo-g) (kk-jj)"



      Array(0) = "blabla "
      Array(1) = "lo-g) "



      So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character



          Dim SplitText = text.Split("(")

      If SplitText.Length > 1 Then
      Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
      'This may be easier for you to read, though:
      'Return text.Split("(")(0) & "(" & text.Split("(")(1)
      End If

      Return text





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).



        Essentially splitting your string into this:
        "blabla (lo-g) (kk-jj)"



        Array(0) = "blabla "
        Array(1) = "lo-g) "



        So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character



            Dim SplitText = text.Split("(")

        If SplitText.Length > 1 Then
        Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
        'This may be easier for you to read, though:
        'Return text.Split("(")(0) & "(" & text.Split("(")(1)
        End If

        Return text





        share|improve this answer












        Since you want to avoid RegEx, this is a simpler/easier to read version I think of what you're trying to accomplish with your loop through each character. Basically you split the string into an array using the ( character as the dividers. So, they need to be re-added but it's nominal since you only need the 1 included (or not).



        Essentially splitting your string into this:
        "blabla (lo-g) (kk-jj)"



        Array(0) = "blabla "
        Array(1) = "lo-g) "



        So, Array(0) & "(" & Array(1) = "blabla (lo-g)", or simply returns the whole string if it counts <= 1 ( character



            Dim SplitText = text.Split("(")

        If SplitText.Length > 1 Then
        Return String.Format("{0}({1}", text.Split("(")(0), text.Split("(")(1))
        'This may be easier for you to read, though:
        'Return text.Split("(")(0) & "(" & text.Split("(")(1)
        End If

        Return text






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 15:49









        Nathan Champion

        2269




        2269






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229469%2fremove-what-is-second-parentheses-of-a-string-vb-net%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Liste der Kulturdenkmale in Wilsdruff

            Android Play Services Check