Count occurrences of values, like @@?
<p>I have created an expandable textarea. The number of characters of the content are counted and the row numbers of the textarea is calculated and modified.  This works really well.  But, when the user manually hits enter, which is a single character, no row is added.  </p>

<p>I want to change it so that users can create their own paragraphs by adding @@ before a new paragraph.  This will be saved to a database. When I output it from the database, I'll replace the @@ with <code>&lt;br /&gt;&lt;br /&gt;</code>.  </p>

<p>Here's the function I am using to calculate the row numbers:</p>

<pre><code>function getRowCount(NumCharacters) {
    var NewRows = NumCharacters / 40;
    NewRows = parseInt(NewRows) + 1;
    return NewRows;
}
</code></pre>

<p>There are 40 characters per row. Each time the user hits another 40 characters, another row is added.  </p>

<p>In my JavaScript, when a user hits @@, I need to ad an extra row to the row count.</p>

<p>How do I using JavaScript to search and count the number of times I find the @@ sequence? and add a row for each time? </p>

<p>++++++++++++++++++++++++++++++++++++++++++</p>

<p>I have tried a few of the answers below. Two of them work really well and are readable and simple.  Both, though, produce an error that I can't quite work around. Firebug tells me:</p>

<pre><code>ThisText.match(/@@/g) is null
</code></pre>

<p>Yeah, I KNOW it's null. There's no @@'s to be found.</p>

<p>This throws an error:</p>

<pre><code>var MyString = "Would you like to help me today?";
ExtraRows = MyString.match(/@@/g).length + 1;
</code></pre>

<p>This does NOT throw an error:</p>

<pre><code>var MyString = "Would you like to @@help me today?";
ExtraRows = MyString.match(/@@/g).length + 1;
</code></pre>

<p>So, how do I get rid of the error that seems to occur when there are no @@'s to be found?</p>
