Retrieve object method
<p>I have an "object" with the following typo within a <code>string</code>: <code>{myObjectIdIKnow?someInfo,{someBracedInfo},{someOtherBracedInfo},someInfo,...,lastInfo}</code>.</p>

<p>I want to retrieve its content (i.e. from <code>someInfo</code> to <code>lastInfo</code>).</p>

<p>Following, the function I built:</p>

<pre><code>def retrieveMyObject(line: String, myObjectId: String) =
{
    if (line.contains(myObjectId))
    {
        var openingDelimiterCount = 0
        var closingDelimiterCount = 0
        val bit = iLine.split(myObjectIdIKnow).last

        var i = -1
        do
        {
            i += 1
            if (bit(i).equals("{")) openingDelimiterCount += 1
            else if (bit(i).equals("}")) closingDelimiterCount += 1
        } while (lDelimiterOpeningCount &gt;= closingDelimiterCount)

        if (i.equals(0)) bit
        else bit.splitAt(i)._1
    }
}
</code></pre>

<p>I match with my <code>myObjectId</code> and browse through each character of the input line to check if it is a brace delimiter or not, then compare the numbers of <code>{</code> and <code>}</code>: if the second is bigger than the first, it means I reached the end of my content and thus I retrieve it.</p>

<p>It does not seem like a good method at all and I was wondering what better way could I do it?</p>