Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:39:49+00:00 2026-06-13T06:39:49+00:00

EDIT: Found the solution – /** * Returns the arguments of the method. Ensures

  • 0

EDIT: Found the solution –

/**
 * Returns the arguments of the method. Ensures inner methods are intact.
 *
 * @param fullMethod full method string
 * @return arguments of the method
 */
public static String[] getArguments(String fullMethod) {
    String innerFirstBrackets = fullMethod.substring(fullMethod.indexOf("(") + 1, fullMethod.lastIndexOf(")"));
    if (innerFirstBrackets.contains("(") && innerFirstBrackets.contains(")")) {
        List list = new List();
        int count = 0;
        int lastComma = 0;
        for (int x = 0; x < innerFirstBrackets.length(); x++) {
            if (innerFirstBrackets.charAt(x) == '(') {
                count ++;
            } else if (innerFirstBrackets.charAt(x) == ')') {
                count --;
            }
            if (innerFirstBrackets.charAt(x) == ',' || x == innerFirstBrackets.length() - 1) {
                if (count == 0) {
                    list.add(innerFirstBrackets.substring((lastComma == 0 ? -1 : lastComma) + 1,
                            (x == innerFirstBrackets.length() - 1 ? x + 1 : x)).trim());
                    lastComma = x;
                }
            }
        }
        return list.getItems();
    } else {
        // No inner methods
        return innerFirstBrackets.split(",");
    }
}

I am trying to get the arguments inside of a String representation of a method. So far I have succeeded in doing it in most cases, but it does not work for certain cases.

Here is the code I currently have :

/**
 * Returns the arguments of the method. Ensures inner methods are intact.
 *
 * @param fullMethod full method string
 * @return arguments of the method
 */
public static String[] getArguments(String fullMethod) {
    String innerFirstBrackets = fullMethod.substring(fullMethod.indexOf("(") + 1, fullMethod.lastIndexOf(")"));
    if (innerFirstBrackets.contains("(") && innerFirstBrackets.contains(")")) {
        List list = new List();
        boolean first = false, second = false;
        int lastComma = 0;
        for (int x = 0; x < innerFirstBrackets.length(); x++) {
            if (innerFirstBrackets.charAt(x) == '(') {
                first = !second;
            } else if (innerFirstBrackets.charAt(x) == ')') {
                second = true;
            }
            if (first && second) {
                first = second = false;
            }
            if (innerFirstBrackets.charAt(x) == ',' || x == innerFirstBrackets.length() - 1) {
                if (!first) {
                    list.add(innerFirstBrackets.substring((lastComma == 0 ? -1 : lastComma) + 1,
                            (x == innerFirstBrackets.length() - 1 ? x + 1 : x)).trim());
                    lastComma = x;
                }
            }
        }
        return list.getItems();
    } else {
        // No inner methods
        return innerFirstBrackets.split(",");
    }
}

This works when there is a method as an argument, but does not work when multiple arguments with methods as their arguments are there. This isn’t a common occurrence, but I don’t like having a vulnerability in my code.

Example of method that works

get(get(1,2));

or

get(get(get(get(1,2))));

or

get(get(1),get(1));

But it will not work when something like this is given

get(get(get(1)),get(1));

I’m not sure how to find the sister parenthesis instead of just finding the next parenthesis. (If you don’t know what I mean by sister parenthesis, think about how on most IDEs, when you highlight one parenthesis, the other is automatically highlighted. EX. enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:39:50+00:00Added an answer on June 13, 2026 at 6:39 am

    I’m not sure I understand why commas are a problem for your algorithm. What you can do is start scanning characters to the right (assuming that you’re starting at a ( left parenthesis), initialise a counter to 0, and:

    • Increment the counter every time you encounter a (
    • Decrement the counter every time you encounter a )

    When the counter reaches zero again, you’ve found the matching pair. The only thing you need to take care of is quoted strings where the code has random parentheses inside single or double quotes (you won’t want to apply those to your counter).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[edit] Found the solution. Reinstall EVERYTHING - xcode, mono, monodevelop and monotouch. Now it
EDIT I Found the solution ! credit goes entirely to the assistance I received
EDIT: I found the solution, see below My first post on StackOverFlow. However I
EDIT: I found a solution for this, you can read it in my answer
Edit: I found a solution here http://mysql.bigresource.com/Track/mysql-8TvKWIvE/ assuming select takes a long time to
-Edit: Solution Found- Figured it out after some heavy searching - one person (I
Edit: I found the solution here SDWebImage : setImageWithURL fails when used to set
EDIT : I found classloader leak in my webapplication. It boils down to 3rd
EDIT: I've found what's causing the issue, but I don't know why and I
EDIT 9-3-10: I found this blog entry recently that was very enlightening. http://optimizermagic.blogspot.com/2007/12/outerjoins-in-oracle.html There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.