title: Count number of commas within a string except for commas between double quotes
body: <p>I have the following function to count the number of commas (or any other character) in a String without counting those inside double quotes. I want to know if there's a better way to achieve this or even if you can find some case where this function can crash.</p>
  
  <pre><code>public int countCharOfString(char c, String s) {
      int numberOfC = 0;
      boolean doubleQuotesFound = false;
      for(int i = 0; i &lt; s.length(); i++){
          if(s.charAt(i) == c &amp;&amp; !doubleQuotesFound){
              numberOfC++;
          }else if(s.charAt(i) == c &amp;&amp; doubleQuotesFound){
              continue;
          }else if(s.charAt(i) == '\"'){
              doubleQuotesFound = !doubleQuotesFound;
          }
      }
      return numberOfC;
  }
  </code></pre>
  
  <p>Thanks for any advise</p>