Find string of method in a file
<p>Right now I have this to find a method</p>

<pre><code>def getMethod(text, a, filetype):
    start = a
    fin = a
    if filetype == "cs":
        for x in range(a, 0, -1):
            if text[x] == "{":
                start = x
                break
        for x in range(a, len(text)):
            if text[x] == "}":
                fin = x
                break
    return text[start:fin + 1]
</code></pre>

<p>How can I get the method the index <code>a</code> is in?</p>

<p>I can't just find <code>{</code> and <code>}</code> because you can have things like <code>new { }</code> which won't work</p>

<p>if I had a file with a few methods and I wanted to find what method the index of x is in then I want the body of that method for example if I had the file</p>

<pre><code>private string x(){
    return "x";
}

private string b(){
    return "b";
}

private string z(){
    return "z";
}

private string a(){
    var n = new {l = "l"};
    return "a";
}
</code></pre>

<p>And I got the index of "a" which lets say is 100</p>

<p>then I want to find the body of that method. So everything within <code>{</code> and <code>}</code></p>

<p>So this...</p>

<pre><code>{
    var n = new {l = "l"};
    return "a";
}
</code></pre>

<p>But using what I have now it would return:</p>

<pre><code>                {l = "l"};
    return "a";
}
</code></pre>
